Reputation: 18068
The last E2E test generated by Specflow and run by NUnit is going to be a malevolent one that is going to lockout the user for some time. I want this test to run last in the whole suite.
I've found that there was Order(int)
attribute introduced in NUnit v3, but that seems to do not support what I want, as I would have to add Order
attribute to all other tests because:
Tests with an OrderAttribute argument are started before any tests without the attribute.
Question: Is this is possible to make NUnit run specified test last in the suite(all other existing tests detected in the project)? If yes, then how?
Upvotes: 0
Views: 443
Reputation: 13681
First, the bad news...
There is no global ordering of tests in NUnit. The OrderAttribute
allows you to order tests within a particular fixture or fixtures within a namespace suite.
Even within a particular containing suite, there is no way to make a test run last, unless you add the order attribute on every test.
Even if the first two limitations were removed, ordering does not guarantee that earlier tests have finished before a test is started. If tests are being run in parallel, that last test would be started as soon as there was a free thread to run it. I'm not clear if that's a problem for you, however.
The slightly better news is that are a couple of workarounds.
You can run a OneTimeTearDown
method at the end of the run. To do that, you need to create a SetUpFixture
outside of any defined namespace in your assembly. Place a [OneTimeTearDown]
attribute on a method in that fixture and put the test code for that final test there. One drawback of this is that any assertion failures are not reported as "Failures" but as "Errors." However, this may not matter to you.
A second, cleaner workaround is to put that one test in a separate assembly. Run that assembly in your CI script only after the first assembly has run. You can also include both assemblies on the command-line for nunit3-console. If you specify --agents=1
The two assembly processes will run sequentially, in the order listed on the command-line.
Upvotes: 1