简体   繁体   English

确定高级方法的单元测试代码覆盖率

[英]Deciding on unit test code coverage for higher level methods

When I have a method like below, 当我有以下方法时,

double Process(double payable)
{
    var step1Result = Step1(payable);
    var step2Result = Step2(step1Result);
    return Step3(step2Result);
}

is it required to have a unit test for Process() when I already have unit tests for the inner three public methods? 我已经对内部三个公共方法进行单元测试时,是否需要对Process()进行单元测试? If the answer is not required, then does it mean that the Process() method has to be maintained through manual code review? 如果不需要答案,那么这是否意味着必须通过手动代码审查来维护Process()方法?

If Process is public then Yes, you will need unit tests for Process. 如果Process是公共的,则Yes,您将需要Process的单元测试。 If someone is fixing a bug and forgets to call Step2, Process will not work anymore. 如果有人正在修复错误并忘记致电Step2,则Process将不再起作用。 If you have written code, it has to be tested. 如果您已编写代码,则必须对其进行测试。

If it is not public, then as long as it is being covered via some other method calling it, for example, another public method then you should be fine. 如果它不是公共的,那么只要它被其他一些调用它的方法(例如,另一个公共方法)覆盖,那么您就可以了。 Basically if the Process method is being used and you put a breakpoint and run all your tests and it does not hit the breakpoint, then that means it is not covered and tested. 基本上,如果正在使用Process方法,并且您设置了一个断点并运行所有测试,但没有达到断点,则意味着该方法没有涉及和测试。 Of course you can use visual studio's test coverage to indicate if it is covered instead of using a breakpoint. 当然,您可以使用Visual Studio的测试覆盖率来指示是否覆盖了它,而不是使用断点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM