When estimating (story points) a story that consists on extending a current functionality with a known tech-debt, should we consider the effort that will be spent to refactor the current code or should we estimate independently of this tech-debt?
In agile if you can do it with out the change then you should not make the change as part of the story. So in that case you would not include the points for the tech debt.
You score the fastest way you can properly complete the story. If taking on the tech debt will speed up the story ie tech debt + story = less time than doing the story with out the tech debt then absolutely you should choose the route that includes the tech debt. But if the story is 3 with out tech debt but 5 with the tech debt then you choose the 3. You could still choose to go the route of clearing the tech debt but it will have an impact on your velocity.
Your estimates should certainly take into account the technical debt. The point of estimating stories is to get an indication of how much effort it will take to accomplish something, and technical debt definitely contributes to that. In fact, you should take everything that might effect the time/effort it takes to implement a story in your estimates (for example, learning the business domain).
Sometimes, when there is a lot of refactoring work to be done, I've added a separate sub-task under a story, and estimated that accordingly. Otherwise, refactoring and dealing with technical debt is going to be a natural part of every story. It should be estimated accordingly.
Let's try both:
- Without Tech Debt: When work commences and you KNOW you'll have to refactor the code to make it work you'll probably decrease your velocity - since the overall complexity was underestimated
- With Tech Debt: You'll increase the 'story point' score since it'll link to the tech debt and "make that explicit" to everyone and could be factored into existing velocity calculations, so to speak.
So, what should you choose? I'd go for #2 since that makes explicit what the story entails, is more realistic a picture and exposes the 'hidden' jobs that may be lurking below (devils in the details, perhaps).
If you do go with #1 the team may be questioned for decreasing velocity and 'not bringing up the tech-debt fix' in the meeting. Just keep it clear - estimate with tech debt and your team will be happy (and so will the PM - a debt would be paid off since something valuable is preceded by it :)