79054

Run TestFixtures in Order with NUnit

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?

Answer1:

Ok, so if I understand you correctly, you want to order test across multiple TestFixtures. So in this case, you don't want to use the OrderedTestFixture because that was specifically created to NOT run test across multiple fixtures. If you look at my GitHub repo from the earlier question, you'll want to follow the Example 2 code. Note that in this case you should only use the OrderedTest attribute - using Test will throw the whole thing off because then it will just be randomly scheduled by NUnit instead of being ordered through the use of TestCaseData. Refer back to my blog post for more details.

Hope that helps.

Recommend

  • Display the TFS server Build number in the UI of a WPF application
  • How do you use PowerShell to extract Epub meta data (XML)?
  • Mojo::UserAgent get() with userdefined callback
  • Entity Framework Connection String Definition
  • Displaying objects using foreach loop
  • How to make my app singleton application? [duplicate]
  • How can I embed components contained in a dll into an exe so it can be run from memory?
  • Pubnub subscribe stops receiving messages after some time
  • Download an image from url and opening it in an image control in wp7
  • Why does the address of an object change across methods?
  • Load Project Settings from .NET Assembly
  • create a cocossharp project in xamarin
  • Step through an assembly language program one statement at a time
  • Kinect API written solely in Java without native functions?
  • Best GAC Tutorial/Overview? [closed]
  • is this code truly private? (python)
  • Wrap assemblies in .NET?
  • Why can't I use non-integral types with switch [duplicate]
  • Why doesn't a local variable live long enough for thread::scoped?
  • Translating C# to PowerShell in InterIMAP
  • Extract All Possible Paths from Expression-Tree and evaluate them to hold TRUE
  • Trying to string.Join an IList
  • XSLT foreach repeating nodes to flat
  • Cannot get the UserManager class
  • Linq Merge lists
  • List images(01.png) and descriptions(01.txt) from directory
  • Should I or shouldn't I use the CachingConnectionFactory with hornetq 2.4.1
  • x64 applications using gdi+: what are the consequences on performance?
  • Set the selected item in dropdownlist in MVC3
  • D3 nodes and links from JSON with nested arrays of children
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • How to delete a row from a dynamic generate table using jquery?
  • C# - Getting references of reference
  • using HTMLImports.whenReady not working in chrome
  • Authorize attributes not working in MVC 4
  • EntityFramework adding new object to nested object collection
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal