Search code examples
unit-testingvisual-studio-2012nunitvs-unit-testing-framework

When I cancel a unit test run does the currently running test complete?


Can anyone tell me: When I press Cancel in the Test Explorer window during a unit test run, is execution simply terminated there and then, or will the currently running test actually run to completion? (Or does it depend which test adapter is being used?) I'm using VS2012. Some solutions use the Microsoft test adapter, some use NUnit (if it makes a difference).


Solution

  • Two part answer...

    1. It does depend on the particular adapter. The Test Explorer calls the adapter's ITestExecutor.Cancel() method and what happens after that point depends on the adapter.

    2. With respect to NUnit...

      If you are using the NUnit 3 VS adapter and running tests using the NUnit 3 framework, the test is cancelled immediately by aborting the thread(s) that is(are) executing the current test(tests). [Parens because you may be running multiple tests in parallel with NUnit 3.] No teardowns are run.

      If you are using the NUnit [V2] VS adapter, the thread is killed immediately and all execution stops. No teardowns are run.