How to handle the refactoring phase of TDD

夙愿已清 提交于 2019-12-05 09:52:41

Now further suppose that my original test no longer covers the extracted code because the original code now mocks out its dependencies, as is correct for a Unit test.

Mocking dependencies is frequently a good thing to do, but not always, and I wouldn't say it's "correct for a unit test" to mock all dependencies.

In the refactoring step of TDD, you should be changing things in the production code that don't affect the passing of the tests. And you shouldn't be changing the tests at the same time.

You might want to later modify your tests so that the extracted code is tested independently of the original code and is mocked in the original tests.

This can be an indication that your unit tests are not fine-grained enough. Like, you've written integration test, made it pass, and now you're putting unit tests in place.

Or maybe after refactoring you are trying to put tests on something you shouldn't, such as private methods. Refactoring shouldn't change your code coverage anyway.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!