Build/Test Issues

Code coverage shows black bubbles in covered lines when using mspec style line breaks

Started by forki on 12,135 views

Hi,

we are using "MSpec-style line breaks". This means we are writing the Establish, Because and It on one line and the actuacl code on the next. With this style NCrunch is marking the Establish, Because and It lines with black bubbles. That's not really what I would expect. It would be nicer if these bubbles would be green or maybe if there would be no bubbles at all.

    public class when_using_code_coverage_with_mspec_style_line_breaks
    {
        It should_run_this =          // black bubble
            () => 1.ShouldEqual(1);   // green bubble
    }


Cheers,
Steffen
That's easy ;)

Set the color of uncovered bubbles to the color of your background.
So why do they exist at all?
This is happening because of the mechanics of the IL under the hood.

There are a few situations where NCrunch isn't catching code coverage where it should ... many of these are around inline functions and therefore when writing MSpec tests you'll certainly notice it a lot more. I've also seen the coverage fail when working with switch statements.

Turning off the black markers isn't really recommended, as you then lose the ability to tell when you have lines of code that actually aren't covered by tests at all and are a risk to your codebase. For the time being, I'd recommend just ignoring the black marks that you see in your MSpec tests until I can get a fix out :)
So what do the black markers tell me in contrast to no marker?
No marker means that the line you're looking at isn't represented in the .PDB file compiled with your code, so it can never really be considered 'covered' by any test (as it's not physically executable).

You'll notice that this corresponds with areas you're able to place breakpoints in your IDE.

If there is a black marker, it means the line you're looking at it a physical line of code that can be executed while your application is running.

The difference between the two is very important, as black marks indicate that you have code in your system that isn't covered by any test (and may need some attention).
Thanks for the explanation. It helped me a lot.

BTW: I was already able to remove two unused methods, because they consisted of only black lines.

Cheers,
Steffen
No problem. I'm glad it's adding value! :)

Post a reply

Log in to reply.