public void test(int a)
{
if (a<=3)
{...}
else if (3<a && a<=8)
{...}
else
{...}
}
The above code is typed in vs 2010 and create UT for it. I tried to set the parameter a to be 2,3,4,8,9. seems it already covers all the code. but after running the UT, the code coverage开发者_运维问答 still not be up to 100%. Any suggestion will be very appreciate!
It is not possible for the 3<a
test to come out false (because the first test has already disposed of that), so the jump from 3<a
to the bottom else
block is never executed.
The fact that you cannot cover the block of code with a test is often a good indication that you may simplify your code without losing any of the execution paths. Consider the following code that does the same thing with 100% coverage:
public void test(int a)
{
if (a <= 3)
{
}
else if (a <= 8)
{
}
else
{
}
}
精彩评论