NUnit, TestDriven.Net: Duplicate test results with partial test classes
Asked Answered
B

1

7

I just discovered that I was getting twice the number of tests run that I should've been getting. Discovered it when a test broke and I got two identical test failures. Same test, same everything. Got me quite confused, but managed to narrow it down to a certain test class that was a partial class.

The reason it was a partial class was that I had split a test class in two, just to make it a bit more clean. The class under test had a certain method that required a long range of tests and I thought it would be cleaner to have those in a separate file. But since there was one or two helper methods used I figured I could just make the class partial so both files still had access to those methods.

The test framework is NUnit and the tests was run by using TestDriven.Net. Ran the tests both from inside a single test method (reported two tests passed instead of one), on the class (got twice the number of tests passed) and on the whole test project.

Managed to fix the issue by making the classes not partial and just duplicating those tiny helper methods (might move those to a separate helper class or something later).

Now... why on earth is this happening? I thought partial classes were compiled into a single class? Is this an issue with partial classes in general, NUnit, Test-Driven.net or something completely different?

Beverle answered 19/1, 2010 at 13:50 Comment(0)
D
4

You probably put the [TestFixture] attribute in both files of the partial class. This will cause TestFixture to be emitted twice in the IL class definition and NUnit will run the same test code twice. You should only add [TestFixture] in one of the files for your partial class.

Demit answered 19/1, 2010 at 14:16 Comment(2)
Ooooh. That might have something to do with it yes. But why can the TestFixture attribute be added twice to a class? That just doesn't make sense... or is it a reason for that to be possible?Beverle
Got to test it now, and removing the TestFixture attribute from one of the partial classes fixed the issue :)Beverle

© 2022 - 2024 — McMap. All rights reserved.