I have concurrency problems running my Nunit tests because they run all in parallel. I would like to know if it's possible to run in series some of them and how.
Asked
Active
Viewed 227 times
2
-
1What you ask is the [default behavior* inside an assembly](https://docs.nunit.org/articles/nunit/technical-notes/usage/Framework-Parallel-Test-Execution.html). Parallel execution occurs [only if you have multiple test assemblies](https://docs.nunit.org/articles/nunit/technical-notes/usage/Engine-Parallel-Test-Execution.html) - each assembly is run by a separate NUnit rrunner. Is that the case here? – Panagiotis Kanavos Mar 31 '21 at 09:51
-
@PanagiotisKanavos my case is this: i have one [TestFixture] class with multiple [Test] method. One test for example write a new record on a db and after that, checks if this new record is added or not. Another test does the same thing writing on the same db. Sometimes tests fails, I suppose because of tests run in parallel. I'd like to avoid this behaviour. – tibe Mar 31 '21 at 16:01
-
1Tthe tests worked beautifully - they revealed that you code has concurrency issues. Databases are built to handle hundreds if not thousands of concurrent connections on a single box. EIther the app code is bad or the test code is bad. You need to find and fix that bug, not cover it up – Panagiotis Kanavos Apr 01 '21 at 06:37
-
1For example, if you insert a record in a database and try to retrieve the generated ID with `IDENT_CURRRENT` you can easily get the latest ID generated by *another* connection. If you use MAX(ID), it's even worse. If you use the `OUTPUT` clause of `INSERT`, there won't be any problems – Panagiotis Kanavos Apr 01 '21 at 06:40
-
1In any case, I posted the links to the docs that explain that only *assemblies* run in parallel, not tests, and how to alter this behavior. This will cover up the bug and allow the tests to pass. The bug will still affect production though, almost immediately. If two concurrent tests cause bad behavior, imagine what would happen with 10 concurrent clients/requests per second, over a week – Panagiotis Kanavos Apr 01 '21 at 06:43
-
@PanagiotisKanavos I didn’t describe my case well, I thought my tests under the same [TestFixture] ran in parallel, so there were situations where one test read data written by another, but i was wrong and i found the bug. I figured out how tests work, thank you so much for your suggestions!!! – tibe Apr 01 '21 at 12:19
-
1This https://stackoverflow.com/questions/35983016/nunit-3-forbid-tests-to-run-in-parallel might be of use. – bytedev Jun 04 '21 at 07:11