public void RunTestsForTestShouldRunTestsInTheParentDomainsApartmentState() { var testCase1 = this.GetTestCase(typeof(DummyTestClassWithDoNotParallelizeMethods), "TestMethod1"); var testCase2 = this.GetTestCase(typeof(DummyTestClassWithDoNotParallelizeMethods), "TestMethod2"); var testCase3 = this.GetTestCase(typeof(DummyTestClassWithDoNotParallelizeMethods), "TestMethod3"); var testCase4 = this.GetTestCase(typeof(DummyTestClassWithDoNotParallelizeMethods), "TestMethod4"); ////testCase3.SetPropertyValue(MSTest.TestAdapter.Constants.DoNotParallelizeProperty, true); testCase4.SetPropertyValue(MSTest.TestAdapter.Constants.DoNotParallelizeProperty, true); TestCase[] tests = new[] { testCase1, testCase2, testCase3, testCase4 }; this.runContext.MockRunSettings.Setup(rs => rs.SettingsXml).Returns( @"<RunSettings> <MSTest> <Parallelize> <Workers>3</Workers> <Scope>MethodLevel</Scope> </Parallelize> </MSTest> </RunSettings>"); try { MSTestSettings.PopulateSettings(this.runContext); this.TestExecutionManager.RunTests(tests, this.runContext, this.frameworkHandle, new TestRunCancellationToken()); Assert.AreEqual(1, DummyTestClassWithDoNotParallelizeMethods.ThreadApartmentStates.Count); Assert.AreEqual(Thread.CurrentThread.GetApartmentState(), DummyTestClassWithDoNotParallelizeMethods.ThreadApartmentStates.ToArray()[0]); } finally { DummyTestClassWithDoNotParallelizeMethods.Cleanup(); } }
public void RunTestsForTestShouldRunNonParallelizableTestsSeparately() { var testCase1 = this.GetTestCase(typeof(DummyTestClassWithDoNotParallelizeMethods), "TestMethod1"); var testCase2 = this.GetTestCase(typeof(DummyTestClassWithDoNotParallelizeMethods), "TestMethod2"); var testCase3 = this.GetTestCase(typeof(DummyTestClassWithDoNotParallelizeMethods), "TestMethod3"); var testCase4 = this.GetTestCase(typeof(DummyTestClassWithDoNotParallelizeMethods), "TestMethod4"); testCase3.SetPropertyValue(MSTest.TestAdapter.Constants.DoNotParallelizeProperty, true); testCase4.SetPropertyValue(MSTest.TestAdapter.Constants.DoNotParallelizeProperty, true); TestCase[] tests = new[] { testCase1, testCase2, testCase3, testCase4 }; this.runContext.MockRunSettings.Setup(rs => rs.SettingsXml).Returns( @"<RunSettings> <MSTest> <Parallelize> <Workers>2</Workers> <Scope>MethodLevel</Scope> </Parallelize> </MSTest> </RunSettings>"); try { MSTestSettings.PopulateSettings(this.runContext); this.TestExecutionManager.RunTests(tests, this.runContext, this.frameworkHandle, new TestRunCancellationToken()); Assert.AreEqual(2, DummyTestClassWithDoNotParallelizeMethods.ParallelizableTestsThreadIds.Count); Assert.AreEqual(1, DummyTestClassWithDoNotParallelizeMethods.UnParallelizableTestsThreadIds.Count); Assert.IsTrue(DummyTestClassWithDoNotParallelizeMethods.LastParallelizableTestRun < DummyTestClassWithDoNotParallelizeMethods.FirstUnParallelizableTestRun); } finally { DummyTestClassWithDoNotParallelizeMethods.Cleanup(); } }