diff --git a/src/Adapter/MSTest.CoreAdapter/Execution/TestExecutionManager.cs b/src/Adapter/MSTest.CoreAdapter/Execution/TestExecutionManager.cs index 1d618644ef..c48577a677 100644 --- a/src/Adapter/MSTest.CoreAdapter/Execution/TestExecutionManager.cs +++ b/src/Adapter/MSTest.CoreAdapter/Execution/TestExecutionManager.cs @@ -408,6 +408,9 @@ private void CacheSessionParameters(IRunContext runContext, ITestExecutionRecord var testRunParameters = RunSettingsUtilities.GetTestRunParameters(runContext.RunSettings.SettingsXml); if (testRunParameters != null) { + // Clear sessionParameters to prevent key collisions of test run parameters in case + // "Keep Test Execution Engine Alive" is selected in VS. + this.sessionParameters.Clear(); foreach (var kvp in testRunParameters) { this.sessionParameters.Add(kvp); diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestExecutionManagerTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestExecutionManagerTests.cs index ffd2f09424..601a6d10f8 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestExecutionManagerTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestExecutionManagerTests.cs @@ -296,6 +296,38 @@ public void RunTestsForTestShouldPassInDeploymentInformationAsPropertiesToTheTes testablePlatformService.MockSettingsProvider.Verify(sp => sp.GetProperties(It.IsAny()), Times.Once); } + [TestMethodV1] + public void RunTestsShouldClearSessionParametersAcrossRuns() + { + var testCase = this.GetTestCase(typeof(DummyTestClass), "PassingTest"); + + TestCase[] tests = new[] { testCase }; + this.runContext.MockRunSettings.Setup(rs => rs.SettingsXml).Returns( + @" + + + + + "); + + // Trigger First Run + this.TestExecutionManager.RunTests(tests, this.runContext, this.frameworkHandle, new TestRunCancellationToken()); + + // Update runsettings to have different values for similar keys + this.runContext.MockRunSettings.Setup(rs => rs.SettingsXml).Returns( + @" + + + + + "); + + // Trigger another Run + this.TestExecutionManager.RunTests(tests, this.runContext, this.frameworkHandle, new TestRunCancellationToken()); + + Assert.AreEqual(DummyTestClass.TestContextProperties["webAppUrl"], "http://updatedLocalHost"); + } + #endregion #region Run Tests on Sources @@ -620,7 +652,7 @@ public void RunTestsForTestShouldRunNonParallelizableTestsSeparately() Assert.AreEqual(2, DummyTestClassWithDoNotParallelizeMethods.ParallelizableTestsThreadIds.Count); Assert.AreEqual(1, DummyTestClassWithDoNotParallelizeMethods.UnParallelizableTestsThreadIds.Count); - Assert.IsTrue(DummyTestClassWithDoNotParallelizeMethods.LastParallelizableTestRun.TimeOfDay.TotalMilliseconds < DummyTestClassWithDoNotParallelizeMethods.FirstUnParallelizableTestRun.TimeOfDay.TotalMilliseconds); + Assert.IsTrue(DummyTestClassWithDoNotParallelizeMethods.LastParallelizableTestRun.TimeOfDay.TotalMilliseconds <= DummyTestClassWithDoNotParallelizeMethods.FirstUnParallelizableTestRun.TimeOfDay.TotalMilliseconds); } finally {