开发者

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

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).

No开发者_Python百科w... 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜