Why are my NUnit tests running in a different order than they are listed?

Why are my NUnit tests running in a different order than they are listed?

And what does the execution of the execution depend on?

+2


a source to share


3 answers


It depends on how the runner is happy with them after being reflected on your test build. Every runner can do it differently.

For example, the Reshaper runner works in alphabetical order.



But the main problem here is that NUnit tests should not have sequential provisions or dependencies.

If you need tests to depend on other tests, use MbUnit. This is an example of a fixture dependency using DependsOnAttribute.

+3


a source


Any unit test runner will probably reflect the test fixture class and look for all methods with a specific attribute (or that follows some naming convention). The order returned by these methods is independent of the order in which they are specified in the source file, so they cannot be executed in the order in which they are defined. This shouldn't be a problem as the unit tests must run independently of each other.



+2


a source


They are performed in alphabetical order as indicated. If you open the test dll in the NUnit GUI slider, you will see the ordering.

Regardless, the order in which unit tests are run should be different . A unit test should be isolated and independent, so order shouldn't be an issue.

+2


a source







All Articles