Let’s say that I’ve been iterating over my feature with TDD. After several red-green-refactor cycles, I ended up with a nicely polished implementation with a part of the SUT encapsulated into some abstraction that provides a reusable piece of logic. There are a bunch of tests that support this piece of reusable logic.
Now, I will work on the next feature that should reuse the same logic, but in a slightly different context.
I don’t want to test-drive this logic test-by-test again, effectively reinventing the wheel, not reusing. If I go for a test-by-test approach, and just add the first test, I cannot just add a reusable code in the implementation, cause it does more than the test currently asserts about. I’m also not a fan of duplicating tests among these two features. I’m after clean tests and best practices.
How do you approach such a problem with TDD?
Maciek Czarnik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.