From 016413500b588c4d72f5f480d90d7c11c50e69f1 Mon Sep 17 00:00:00 2001 From: Arun Mahapatra Date: Thu, 2 Feb 2017 04:40:47 +0530 Subject: [PATCH] Show IFrameworkHandle.SendMessage messages from test adapters. --- .../Execution/BaseRunTests.cs | 11 +++++++--- .../Execution/BaseRunTestsTests.cs | 21 ++++++++++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/BaseRunTests.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/BaseRunTests.cs index d5d43b5877..7b0f8ff399 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/BaseRunTests.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/BaseRunTests.cs @@ -115,6 +115,7 @@ private void SetContext() this.testRunCache, this.testExecutionContext, this.testRunEventsHandler); + this.frameworkHandle.TestRunMessage += OnTestRunMessage; this.executorUrisThatRanTests = new List(); } @@ -227,9 +228,8 @@ internal void Abort() /// internal void Cancel() { - ITestExecutor activeExecutor = this.activeExecutor; isCancellationRequested = true; - if (activeExecutor != null) + if (this.activeExecutor != null) { Task.Run(() => CancelTestRunInternal(this.activeExecutor)); } @@ -239,7 +239,7 @@ private void CancelTestRunInternal(ITestExecutor executor) { try { - activeExecutor.Cancel(); + executor.Cancel(); } catch (Exception e) { @@ -261,6 +261,11 @@ private void CancelTestRunInternal(ITestExecutor executor) #region Private methods + private void OnTestRunMessage(object sender, TestRunMessageEventArgs e) + { + this.testRunEventsHandler.HandleLogMessage(e.Level, e.Message); + } + private TimeSpan RunTestsInternal() { long totalTests = 0; diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Execution/BaseRunTestsTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Execution/BaseRunTestsTests.cs index af254f3179..fa59604d4c 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Execution/BaseRunTestsTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Execution/BaseRunTestsTests.cs @@ -312,7 +312,6 @@ public void RunTestsShouldInstrumentAdapterExecutionStop() [TestMethod] public void RunTestsShouldReportAWarningIfExecutorUriIsNotDefinedInExtensionAssembly() { - //System.Diagnostics.Debugger.Launch(); var assemblyLocation = typeof(BaseRunTestsTests).GetTypeInfo().Assembly.Location; var executorUriExtensionMap = new List> { @@ -569,6 +568,26 @@ public void RunTestsShouldNotifyItsImplementersOfAnyExceptionThrownByTheExecutor Assert.IsTrue(isExceptionThrown.HasValue && isExceptionThrown.Value); } + [TestMethod] + public void RunTestsShouldReportLogMessagesFromExecutors() + { + var assemblyLocation = typeof(BaseRunTestsTests).GetTypeInfo().Assembly.Location; + var executorUriExtensionMap = new List> + { + new Tuple(new Uri(BaseRunTestsExecutorUri), assemblyLocation) + }; + this.runTestsInstance.GetExecutorUriExtensionMapCallback = (fh, rc) => executorUriExtensionMap; + this.runTestsInstance.InvokeExecutorCallback = + (executor, executorUriTuple, runcontext, frameworkHandle) => + { + frameworkHandle.SendMessage(TestMessageLevel.Error, "DummyMessage"); + }; + + this.runTestsInstance.RunTests(); + + this.mockTestRunEventsHandler.Verify(re => re.HandleLogMessage(TestMessageLevel.Error, "DummyMessage")); + } + #endregion #region Private Methods