NUnit 3: Forbid tests to run in parallel

前端 未结 2 1105
小鲜肉
小鲜肉 2021-02-02 12:45

I have the latest NUnit(3.2.0) installed and I have all my tests run in parallel. It might look like desirable behavior but I didn\'t ask for it and actually it broke some of my

相关标签:
2条回答
  • 2021-02-02 13:28

    NUnit does not guarantee that all of your tests will run on the same thread, so the observation that your tests are running on different threads does not mean they are running in parallel.

    The documentation only states that tests will run sequentially or in parallel. You may construe that this means they run on the same thread, but there are many reasons that the internal implementation might require tests to run on different threads. Timeout is an example, where we spawn a thread and kill it if the test times out, but there are many others.

    Parallel test runs are new to NUnit 3, so the internal implementation changed from NUnit 2. An attribute that forces all tests within a thread to run on the same thread might be useful, so feel free to submit an enhancement request.

    Sorry, I am unfamiliar with MVVM Light, so I can't suggest ways to marshal back to the OneTimeSetup thread.

    Update - Since this is a common usage with web and async, the NUnit team has decided to provide an attribute that will demand tests be run on the same thread as the fixture's OneTimeSetup. This will be in the next release, either 3.4, or in a hotfix 3.2.1 release. If you want to track progress, see the issue and the pull request.

    Update 2 - You can now add SingleThreadedAttribute to a TestFixture to indicate to the runner that the OneTimeSetUp, OneTimeTearDown and all the child tests must run on the same thread.

    0 讨论(0)
  • 2021-02-02 13:48

    You can prevent tests from running in parallel by adding the [NonParallelizable] attribute, which can be added in test, class and assembly level.

    0 讨论(0)
提交回复
热议问题