public void TestCancel() { var executor = new TestExecutor(); var recorder = new MockTestExecutionRecorder(); var runContext = new MockRunContext(); var expectedTests = TestInfo.TestAdapterATests.Union(TestInfo.TestAdapterBTests).ToArray(); var testCases = expectedTests.Select(tr => tr.TestCase); var thread = new System.Threading.Thread(o => { executor.RunTests(testCases, runContext, recorder); }); thread.Start(); // One of the tests being run is hard coded to take 10 secs Assert.IsTrue(thread.IsAlive); System.Threading.Thread.Sleep(100); executor.Cancel(); System.Threading.Thread.Sleep(100); // It should take less than 10 secs to cancel // Depending on which assemblies are loaded, it may take some time // to obtain the interpreters service. Assert.IsTrue(thread.Join(10000)); System.Threading.Thread.Sleep(100); Assert.IsFalse(thread.IsAlive); // Canceled test cases do not get recorded Assert.IsTrue(recorder.Results.Count < expectedTests.Length); }