Build/Test Issues

Incorrect coverage detection with NUnit TestCaseSource

Started by VNicholson on 6,213 views

I use a number of TestCaseSource based unit tests that use reflection to cover a set of common functionality in some of my classes. NCrunch 2.2.0.2 (in Visual Studio 2012) seems to have issues with coverage colouring and population of the 'Tests Covering' context menu for these tests.

In a single TestFixture I have two source private static IEnumerable<TestCaseData> properties and four test functions each referencing one of those properties with a TestCaseSource attribute. I get appropriate colouring and 'Tests Covering' menus for one of those four test functions, but the other three are wrong. The three that aren't working appear with the 'no coverage' colouring and while they have non-zero 'Tests Covering' menu headers, none of the tests are listed therein (see screenshot).

(- BROKEN LINK -)[img](- BROKEN LINK -)[/img][/url]

If I separate the four test functions into four separate test fixtures, this seems to work okay.

Is there a bug or known limitation here that means I can't have more than one function in a test fixture that is decorated with a TestCaseSource attribute?

Edited

Hi, thanks for sharing this issue!

The only thing that springs to mind is that tests re-using the same TestCaseSource have a higher chance of being described/generated under the same name as each other. Do the tests show uniquely inside the NCrunch Tests Window? Because NCrunch needs a certain way to identify tests over multiple execution runs, it's important that tests are named uniquely.

Is there any chance you could share some sample code with me? A short compiling snippet showing two of the problem tests and the TestCaseSource they are using would be really great - I'm sure I could give a clear explanation of what is happening with this, and perhaps arrange a fix if possible.


Cheers,

Remco
Thanks for the quick response Remco, your theory was spot on. I was using a Type name as the test name and because four test methods were sharing only two sources there was a lot of overlap going on. I refactored things so that I have four test case sources now, each with a unique name prefix and the coverage colouring and 'Tests Covering' menus are working as expected.

Edited

Great stuff! Good work on the refactoring :)

Cheers,

Remco

Post a reply

Log in to reply.