Build/Test Issues

TestFixtureSetUp not running for nested class, bug?

Started by WinMan on 5,407 views

We have this setup:

[TestFixture]
public class ATest
{

	[TestFixtureSetUp]
	public void ParentFixtureSetup()
        {
		// Some setup	
	}

        [TestFixture]
        public class NestedClass
        {
		[Test]
		public void SomeTest()
		{
			//Fails since the setup in  ParentFixtureSetup did not run
		}
   
	}
}


This runs ok in NUnit test runner. Is this a bug?
Hi, thanks for posting!

All actions in NCrunch revolve around the tests themselves, where fixtures are merely containers of tests. It isn't logically possible for an empty fixture to represented in NCrunch, and as such it will be ignored by NCrunch during test discovery. Every fixture in NCrunch must have at least one test to be detected. As not all frameworks behave like this (i.e. later versions of NUnit), you could probably consider it a bug - but it's so deeply tied in to the way that NCrunch works that I don't expect this to ever change in future.

I'm not completely sure as to the way your test is structured, but I'm wondering if you're using static state of some kind that is shared between the ParentFixtureSetup() and the nested test. I recommend against this kind of test arrangement as it is actually sequence-dependent execution of two completely different tests - even under NUnit, the ATest fixture can be executed separately from the NestedClass fixture and vice versa.


Cheers,

Remco

Edited

Post a reply

Log in to reply.