I need to have ordered test fixtures in my NUnit c# Application. I have an example on how to run ordered test methods from this page, and I've tried to implement the same logic for test fixtures with the same methods provided in the example application. In our application a test fixture is separated for each class and each test fixture has one test method. Our latest attempt was to use a Parent Test Fixture which inherits from a class called: OrderedTestFixture (the same as in the example), which has the following method:
public IEnumerable<NUnit.Framework.TestCaseData> TestSource
{
get
{
var assembly = Assembly.GetExecutingAssembly();
foreach (var order in methods.Keys.OrderBy(x => x))
{
foreach (var methodInfo in methods[order])
{
MethodInfo info = methodInfo;
yield return new NUnit.Framework.TestCaseData(
new TestStructure
{
Test = () =>
{
object classInstance = Activator.CreateInstance(info.DeclaringType, null);
info.Invoke(classInstance, null);
}
}).SetName(methodInfo.Name);
}
}
}
}
This method is supposed to return, in order, the test methods that will execute. However, even if it returns the test methods in order, it fails to execute them in order.
I'm using the same exact logic as in the App example. An orderedTestAttrribute class that inherits from Attribute that will be placed in every test method like this:
[Test]
[OrderedTest(1)]
[BeforeAfterTest]
public void TestMethod() { }
Does anyone out there have any idea how can I make this work without changing my current implementation of having one testFixture with one test class separately?