public void RunTests_CancelingDuringTestExecution_StopsTestExecution() { List <TestCase> allTestCases = AllTestCasesOfSampleTests; List <TestCase> testCasesToRun = GetTestCasesOfSampleTests("Crashing.LongRunning", "LongRunningTests.Test3"); Stopwatch stopwatch = new Stopwatch(); ITestRunner runner = new SequentialTestRunner(MockFrameworkReporter.Object, TestEnvironment); Thread thread = new Thread(() => runner.RunTests(allTestCases, testCasesToRun, "", "", false, null)); stopwatch.Start(); thread.Start(); Thread.Sleep(1000); runner.Cancel(); thread.Join(); stopwatch.Stop(); Assert.IsTrue(stopwatch.ElapsedMilliseconds > 2000); // 1st test should be executed Assert.IsTrue(stopwatch.ElapsedMilliseconds < 3000); // 2nd test should not be executed }
public void RunTests_CancelingDuringTestExecution_StopsTestExecution() { List<TestCase> allTestCases = TestDataCreator.AllTestCasesOfSampleTests; List<TestCase> testCasesToRun = TestDataCreator.GetTestCasesOfSampleTests("Crashing.LongRunning", "LongRunningTests.Test3"); var stopwatch = new Stopwatch(); var runner = new SequentialTestRunner(MockFrameworkReporter.Object, TestEnvironment); var thread = new Thread(() => runner.RunTests(allTestCases, testCasesToRun, "", "", "", false, null)); stopwatch.Start(); thread.Start(); Thread.Sleep(1000); runner.Cancel(); thread.Join(); stopwatch.Stop(); stopwatch.ElapsedMilliseconds.Should().BeGreaterThan(2000); // 1st test should be executed stopwatch.ElapsedMilliseconds.Should().BeLessThan(3000); // 2nd test should not be executed }
public void RunTests_CancelingDuringTestExecution_StopsTestExecution() { List <TestCase> allTestCases = TestDataCreator.AllTestCasesOfSampleTests; List <TestCase> testCasesToRun = TestDataCreator.GetTestCasesOfSampleTests("Crashing.LongRunning", "LongRunningTests.Test3"); var stopwatch = new Stopwatch(); var runner = new SequentialTestRunner(MockFrameworkReporter.Object, TestEnvironment); var thread = new Thread(() => runner.RunTests(allTestCases, testCasesToRun, "", "", false, null)); stopwatch.Start(); thread.Start(); Thread.Sleep(1000); runner.Cancel(); thread.Join(); stopwatch.Stop(); stopwatch.ElapsedMilliseconds.Should().BeGreaterThan(2000); // 1st test should be executed stopwatch.ElapsedMilliseconds.Should().BeLessThan(3000); // 2nd test should not be executed }
private void DoRunCancelingTests(bool killProcesses, int lower, int upper) { MockOptions.Setup(o => o.KillProcessesOnCancel).Returns(killProcesses); List <TestCase> testCasesToRun = TestDataCreator.GetTestCases("Crashing.LongRunning", "LongRunningTests.Test2"); var stopwatch = new Stopwatch(); var runner = new SequentialTestRunner("", 0, "", MockFrameworkReporter.Object, TestEnvironment.Logger, TestEnvironment.Options, new SchedulingAnalyzer(TestEnvironment.Logger)); var thread = new Thread(() => runner.RunTests(testCasesToRun, false, ProcessExecutorFactory)); stopwatch.Start(); thread.Start(); Thread.Sleep(1000); runner.Cancel(); thread.Join(); stopwatch.Stop(); testCasesToRun.Should().HaveCount(2); MockLogger.Verify(l => l.LogError(It.IsAny <string>()), Times.Never); stopwatch.ElapsedMilliseconds.Should().BeGreaterThan(lower); // 1st test should be executed stopwatch.ElapsedMilliseconds.Should().BeLessThan(upper); // 2nd test should not be executed }
public void RunTests_CancelingDuringTestExecution_StopsTestExecution() { List <TestCase> allTestCases = TestDataCreator.AllTestCasesExceptLoadTests; List <TestCase> testCasesToRun = TestDataCreator.GetTestCases("Crashing.LongRunning", "LongRunningTests.Test2"); var stopwatch = new Stopwatch(); var runner = new SequentialTestRunner("", MockFrameworkReporter.Object, TestEnvironment.Logger, TestEnvironment.Options, new SchedulingAnalyzer(TestEnvironment.Logger)); var executor = new ProcessExecutor(null, MockLogger.Object); var thread = new Thread(() => runner.RunTests(allTestCases, testCasesToRun, "", "", "", false, null, executor)); stopwatch.Start(); thread.Start(); Thread.Sleep(1000); runner.Cancel(); thread.Join(); stopwatch.Stop(); testCasesToRun.Count.Should().Be(2); MockLogger.Verify(l => l.LogError(It.IsAny <string>()), Times.Never); stopwatch.ElapsedMilliseconds.Should().BeGreaterThan(2000); // 1st test should be executed stopwatch.ElapsedMilliseconds.Should().BeLessThan(3000); // 2nd test should not be executed }