简体   繁体   中英

MS Test Code Coverage returning incorrect results

I have written a .Net 4 WPF app in the MVVM pattern and have written several unit tests for the app. I enabled code coverage and enabled instrumentation in the local.testsettings. My issue is that the Code Coverage does not appear to be returning correct results. It shows that 86% of my code is analyzed. However, some of the code that it says is not being hit is hit. To prove it, I put breakpoints on the code and did a Debug of the unit tests. The breakpoints were hit, so the code is definitely being covered. Why would code coverage not see that the code is hit?

I am attempting this with Visual Studio 2010 SP1 and running the tests from the Test view.

Any ideas?

Per request, here is some code. This is the entire class. Code Coverage says the constructor is not hit, but it is. A breakpoint on the "Channel = item;" line is hit when debugging the unit tests.

public class ChannelEventArgs : EventArgs
{
    public ChannelEventArgs(IChannel item)
    {
        Channel = item;
    }

    public IChannel Channel { get; set; }
}

Given only that much information, my educated guess is, that you have a problem with instrumenting the assemblies.

Check the list of items in my answer to: Running NUnit tests in Visual Studio 2010 with code coverage

Especially the first ("instrument in place"), third item (build into a single folder) and last item (command line option /noshadow) would have the effect you described.

I can also think up an odd case in which your tested code loads the respective assembly but then you wouldn't have written a unit test.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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