0

MSTest + Visual Studio generates accessors which appear on the NCover coverage report. They usually have a low coverage in my case. I wonder if I use them in my tests if the method I'm testing will appear as covered in the Accessor but not in the original source code.

If this is the case, it is a problem and I need a solution.

Jader Dias
  • 88,211
  • 155
  • 421
  • 625

2 Answers2

1

The dev team was interested in this issue and created an MSTest private accessor project in VS 2010.

I ran coverage on it in NCover 3 with MSTest, and it appears that these accessors are reflecting the source code, not a generated version of it, at least in our test.

If you'd like to get the test project and try it out, just contact us at support@ncover.com.

Thanks!

NCover Support
  • 271
  • 1
  • 4
0

If I understand your scenario, then any method called by your test will be shown as covered in the source code.

If the test adds accessors, those will also be shown as covered where they appear, but you can filter them out by excluding the get and set methods that are generated.

Here's a link to the syntax for the method exclude:

http://docs.ncover.com/ref/3-0/ncover-console/command-line/profiling-options#em

We've been successful here with the regex .*.get_.*, just as an example.

NCover Support

NCover Support
  • 271
  • 1
  • 4
  • My problem isn't filtering out get and set methods. I'm concerned with my tests running on generated code (accessors) instead of the original source code. – Jader Dias Feb 15 '12 at 16:13
  • OK, sorry to get off-track. If your test calls a method, the code that is loaded in that call will be covered. Typically, test assemblies are excluded, so that you're left with the source code only. Hope this answers your question. – NCover Support Feb 20 '12 at 16:57
  • I think we must study how Visual Studio MSTest Accessors work in order to answer this question then. My guess is that Visual Studio duplicates the code and the code that gets covered isn't the original one, but a modified version. – Jader Dias Feb 22 '12 at 15:25
  • That's interesting. These MSTest auto-generated private accessors apparently use reflection, which would probably result in the behavior you describe, though we haven't tested it here. Sorry I didn't figure that out earlier. I'll talk to the dev team about testing this scenario before the next release. – NCover Support Feb 22 '12 at 18:47