关闭。这个问题需要更多focused .它目前不接受答案。
想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post .
3年前关闭。
Improve this question
这最近一直让我发疯......
什么是重构?
Code refactoring is the process of restructuring existing computer code – changing the factoring – without changing its external behavior.
我们如何确保在重构过程中不会破坏任何东西?
Before refactoring a section of code, a solid set of automatic unit tests is needed. The tests are used to demonstrate that the behavior of the module is correct before the refactoring.
好的。但是,如果我在单元测试中发现代码异味,我该如何继续?比如说,一个做太多事情的测试方法?我如何确保在重构单元测试时不会破坏任何东西?
我需要某种元测试吗?是单元测试一直向下吗?
还是单元测试根本不遵守重构的正常规则?
最佳答案
根据我的经验,有 two reasons to trust tests :
这两个都是在编写测试时发生的事件。如果您保持测试不可变,则可以继续信任它们。
每次修改测试时,它的可信度都会降低。
您可以通过重复上述过程在一定程度上缓解该问题:查看对测试的更改,并临时更改被测系统 (SUT),以便您可以看到测试失败 正如预期的那样 .
修改测试时,保持 SUT 不变。测试和生产代码相互检查,所以 改变一个同时保持另一个锁定 是最安全的。
关于unit-testing - 如何重构单元测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31434305/