質問

I wrote this class that does a few things (perhaps this is a violation of the Single Responsibility Principle). I realize now that some other part of the project needs a piece of that logic and the way I'm going to expose it is to extract a class out of my original System Under Test.

I anticipate being able to do this without having to change any test code, but when I finish, you could argue that the test isn't a unit test anymore. It'll be testing the original class and the class I've extracted. In other words, I'll have one test case, but two systems under test.

Am I supposed to refactor my test code after I'm done? IE: Create an ExtractedClassTest and move all the relevant tests from OriginalClassTest into it? This seems like it could be a little risky: I may lose some coverage in the process, it may not be as simple as moving a test and I'd end up rewriting some test code that I know used to work but may not anymore, etc.

On the other hand, if I leave the OriginalClassTest as-is, I can see this being a test maintenance issue. It'll be a little confusing to find where the ExtractedClass's tests are. Your first impression will be that it doesn't exist. Over time with lots of production code refactorings, this could become a serious issue.

I'm new to TDD so I'd like an expert's advice. Thanks!

正しい解決策はありません

ライセンス: CC-BY-SA帰属
所属していません softwareengineering.stackexchange
scroll top