Running tests in parallel can reduce time otherwise spent waiting for them to complete. This is easy in NUnit, but you must ensure your tests are compatible to prevent unexpected behaviour. Tests should be fully self-contained. While it’s tempting to use setup attributes to reduce code duplication, a new test starting can interfere with tests that are already running if shared variables are unexpectedly altered. It’s also important to remember not all data collections are fully thread-safe and performing write operations from different threads can cause exceptions to be thrown. Finally, if the test runner has capacity to start a new test, it will do so independently of the status of other tests. If a test relies on others completing in a predefined order, it may need rewriting.
Share this post
Parallelise Your NUnit Tests to Be More…
Share this post
Running tests in parallel can reduce time otherwise spent waiting for them to complete. This is easy in NUnit, but you must ensure your tests are compatible to prevent unexpected behaviour. Tests should be fully self-contained. While it’s tempting to use setup attributes to reduce code duplication, a new test starting can interfere with tests that are already running if shared variables are unexpectedly altered. It’s also important to remember not all data collections are fully thread-safe and performing write operations from different threads can cause exceptions to be thrown. Finally, if the test runner has capacity to start a new test, it will do so independently of the status of other tests. If a test relies on others completing in a predefined order, it may need rewriting.