Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Peculiar CodeCoverage Highlighting

When you run tests in Visual Studio (with activated CodeCoverage) the code is highlighted to show which parts of code have been executed and which not.

There are three different kinds of highlighting, Not Touched Area, Touched Area and Partially Touched Area. The following two pseudo codes shows examples in which the code will be partially touched.

if (true || false)

if (false && true)

However, when I run tests I wonder about the highlighting of my code. The blue background indicates that the code has been completely touched, while the dark orange indicates that the code has been partially touched. (The highlight on the last line is current line)

enter image description here

This does not make sense at all. Since the if statement is built up of a logical AND operation it must be completely touched to enter the code for the true statement.

I reckon this is a bug, however, I just wanna be clear that I don't have any misconceptions. Do you see any reason why the if-statement can be partially touched, and though the true statement be raised?

like image 893
Em1 Avatar asked Dec 31 '25 20:12

Em1


1 Answers

My guess is that it is because the if body has never been skipped due to the test variable being true. A conditional and is compiled down to something similar to

if (!test)
    goto afterBody;  // 1
if (!(dummy != null))
    goto afterBody;  // 2
// body
afterBody:
// next statement

The line marked with 1 is never executed, hence your partial coverage.

like image 72
erikkallen Avatar answered Jan 04 '26 13:01

erikkallen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!