From 5a87ef9b8f24d74986a8e6e2400b48872e50bac1 Mon Sep 17 00:00:00 2001 From: Abhishek Kumawat Date: Mon, 19 Feb 2018 16:26:24 +0530 Subject: [PATCH] Exceptions flow to Translation layer (#1434) * Exceptions flow to Translation layer * Unit tests * Unit tests * sortings * sort usings --- .../DesignMode/DesignModeClient.cs | 6 - .../RequestHelper/ITestRequestManager.cs | 6 +- .../ObjectModel/TestResult.cs | 11 - .../ObjectModel/UriDataAttachment.cs | 1 - src/vstest.console/CommandLine/Executor.cs | 10 +- src/vstest.console/Internal/ConsoleLogger.cs | 29 +- .../EnableLoggerArgumentProcessor.cs | 19 +- ...istFullyQualifiedTestsArgumentProcessor.cs | 4 +- .../Processors/ListTestsArgumentProcessor.cs | 4 +- .../RunSpecificTestsArgumentProcessor.cs | 21 +- .../Processors/RunTestsArgumentProcessor.cs | 12 +- .../TestPlatformHelpers/TestRequestManager.cs | 73 ++--- .../DesignMode/DesignModeClientTests.cs | 48 ++++ .../ExecutorUnitTests.cs | 75 ++++++ .../Internal/ConsoleLoggerTests.cs | 142 +--------- ...llyQualifiedTestsArgumentProcessorTests.cs | 26 +- .../ListTestsArgumentProcessorTests.cs | 26 +- .../RunSpecificTestsArgumentProcessorTests.cs | 38 +-- .../RunTestsArgumentProcessorTests.cs | 20 +- .../TestRequestManagerTests.cs | 252 ++++++------------ 20 files changed, 315 insertions(+), 508 deletions(-) diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index 419f6d24d6..6d8f1bb033 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -300,9 +300,6 @@ private void StartTestRun(TestRunRequestPayload testRunPayload, ITestRequestMana { EqtTrace.Error("DesignModeClient: Exception in StartTestRun: " + ex); - // If there is an exception during test run request creation or some time during the process - // In such cases, TestPlatform will never send a TestRunComplete event and IDE need to be sent a run complete message - // We need recoverability in translationlayer-designmode scenarios var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() }; this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload); var runCompletePayload = new TestRunCompletePayload() @@ -331,9 +328,6 @@ private void StartDiscovery(DiscoveryRequestPayload discoveryRequestPayload, ITe { EqtTrace.Error("DesignModeClient: Exception in StartDiscovery: " + ex); - // If there is an exception during test discovery request creation or some time during the process - // In such cases, TestPlatform will never send a DiscoveryComplete event and IDE need to be sent a discovery complete message - // We need recoverability in translationlayer-designmode scenarios var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() }; this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload); diff --git a/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs b/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs index 944a0600fc..db1e20024a 100644 --- a/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs +++ b/src/Microsoft.TestPlatform.Client/RequestHelper/ITestRequestManager.cs @@ -33,8 +33,7 @@ public interface ITestRequestManager : IDisposable /// Discovery payload /// Discovery events registrar - registers and unregisters discovery events /// Protocol related information - /// True, if successful - bool DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscoveryEventsRegistrar disoveryEventsRegistrar, ProtocolConfig protocolConfig); + void DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscoveryEventsRegistrar disoveryEventsRegistrar, ProtocolConfig protocolConfig); /// /// Run Tests with given a test of sources @@ -43,8 +42,7 @@ public interface ITestRequestManager : IDisposable /// Custom testHostLauncher for the run /// RunEvents registrar /// Protocol related information - /// True, if sucessful - bool RunTests(TestRunRequestPayload testRunRequestPayLoad, ITestHostLauncher customTestHostLauncher, ITestRunEventsRegistrar testRunEventsRegistrar, ProtocolConfig protocolConfig); + void RunTests(TestRunRequestPayload testRunRequestPayLoad, ITestHostLauncher customTestHostLauncher, ITestRunEventsRegistrar testRunEventsRegistrar, ProtocolConfig protocolConfig); /// /// Cancel the current TestRun request diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestResult.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestResult.cs index 517fecafb8..a7df5928cf 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestResult.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/TestResult.cs @@ -553,17 +553,6 @@ internal void AddCollectorDataEntries(IEnumerable collectorD { Debug.Assert(collectorDataEntry != null, "'collectorDataEntry' is null"); Debug.Assert(!this.collectorDataEntries.Contains(collectorDataEntry), "The collector data entry already exists in the collection"); -#if DEBUG - // Verify that any URI data attachments in the entry have relative paths - foreach (IDataAttachment attachment in collectorDataEntry.Attachments) - { - UriDataAttachment uriDataAttachment = attachment as UriDataAttachment; - if (uriDataAttachment != null) - { - Debug.Assert(uriDataAttachment.Uri.IsAbsoluteUri, "'collectorDataEntry' contains a URI data attachment with a relative URI"); - } - } -#endif this.collectorDataEntries.Add(collectorDataEntry.Clone(testResultsDirectory, false)); } diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/UriDataAttachment.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/UriDataAttachment.cs index 918a0839a2..e61184b7c7 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/UriDataAttachment.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/ObjectModel/UriDataAttachment.cs @@ -111,7 +111,6 @@ internal UriDataAttachment Clone(string baseDirectory, bool useAbsoluteUri) { Debug.Assert(!string.IsNullOrEmpty(baseDirectory), "'baseDirectory' is null or empty"); Debug.Assert(baseDirectory == baseDirectory.Trim(), "'baseDirectory' contains whitespace at the ends"); - Debug.Assert(Path.IsPathRooted(baseDirectory), "'baseDirectory' is not a rooted path"); if (useAbsoluteUri != this.uri.IsAbsoluteUri) { diff --git a/src/vstest.console/CommandLine/Executor.cs b/src/vstest.console/CommandLine/Executor.cs index 6787a8cf61..09df8bfb6f 100644 --- a/src/vstest.console/CommandLine/Executor.cs +++ b/src/vstest.console/CommandLine/Executor.cs @@ -329,11 +329,19 @@ private bool ExecuteArgumentProcessor(IArgumentProcessor processor, ref int exit } catch (Exception ex) { - if (ex is CommandLineException || ex is TestPlatformException || ex is SettingsException) + if (ex is CommandLineException || ex is TestPlatformException || ex is SettingsException || ex is InvalidOperationException) { EqtTrace.Error("ExecuteArgumentProcessor: failed to execute argument process: {0}", ex); this.Output.Error(false, ex.Message); result = ArgumentProcessorResult.Fail; + + // Send inner exception only when its message is different to avoid duplicate. + if (ex is TestPlatformException && + ex.InnerException != null && + !string.Equals(ex.InnerException.Message, ex.Message, StringComparison.CurrentCultureIgnoreCase)) + { + this.Output.Error(false, ex.InnerException.Message); + } } else { diff --git a/src/vstest.console/Internal/ConsoleLogger.cs b/src/vstest.console/Internal/ConsoleLogger.cs index ee700747c5..6b7f8336f7 100644 --- a/src/vstest.console/Internal/ConsoleLogger.cs +++ b/src/vstest.console/Internal/ConsoleLogger.cs @@ -523,38 +523,11 @@ private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) } #endregion - /// - /// Raises test run errors occured before console logger starts listening error events. - /// - /// - /// - public static void RaiseTestRunError(TestRunResultAggregator testRunResultAggregator, Exception exception) - { - if (Output == null) - { - Output = ConsoleOutput.Instance; - } - - // testRunResultAggregator can be null, if error is being raised in discovery context. - testRunResultAggregator?.MarkTestRunFailed(); - - Output.Error(AppendPrefix, exception.Message); - - // Send inner exception only when its message is different to avoid duplicate. - if (exception is TestPlatformException && - exception.InnerException != null && - string.Compare(exception.Message, exception.InnerException.Message, StringComparison.CurrentCultureIgnoreCase) != 0) - { - Output.Error(AppendPrefix, exception.InnerException.Message); - } - } - /// /// Raises test run warning occured before console logger starts listening warning events. /// - /// /// - public static void RaiseTestRunWarning(TestRunResultAggregator testRunResultAggregator, string warningMessage) + public static void RaiseTestRunWarning(string warningMessage) { if (ConsoleLogger.Output == null) { diff --git a/src/vstest.console/Processors/EnableLoggerArgumentProcessor.cs b/src/vstest.console/Processors/EnableLoggerArgumentProcessor.cs index d54ba419c1..117b098c15 100644 --- a/src/vstest.console/Processors/EnableLoggerArgumentProcessor.cs +++ b/src/vstest.console/Processors/EnableLoggerArgumentProcessor.cs @@ -1,28 +1,21 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System.ComponentModel; -using System.Xml; -using Microsoft.VisualStudio.TestPlatform.Common; -using Microsoft.VisualStudio.TestPlatform.Common.Utilities; - namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors { - using Microsoft.VisualStudio.TestPlatform.Common.Logging; using System; using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Globalization; + using System.Xml; using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities; - - using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources; - using Microsoft.VisualStudio.TestPlatform.CommandLine.Internal; - using Microsoft.VisualStudio.TestPlatform.Client; + using Microsoft.VisualStudio.TestPlatform.Common; using Microsoft.VisualStudio.TestPlatform.Common.Interfaces; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; + using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestPlatform.ObjectModel; - using System.Collections.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; + using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources; /// /// An argument processor that allows the user to enable a specific logger @@ -218,7 +211,7 @@ public static void AddLoggerToRunSettings(string loggerArgument, IRunSettingsPro // Remove existing logger. var existingLoggerIndex = loggerRunSettings.GetExistingLoggerIndex(logger); - if (existingLoggerIndex > 0) + if (existingLoggerIndex >= 0) { loggerRunSettings.LoggerSettingsList.RemoveAt(existingLoggerIndex); } diff --git a/src/vstest.console/Processors/ListFullyQualifiedTestsArgumentProcessor.cs b/src/vstest.console/Processors/ListFullyQualifiedTestsArgumentProcessor.cs index 7f2128651e..4bd057f39c 100644 --- a/src/vstest.console/Processors/ListFullyQualifiedTestsArgumentProcessor.cs +++ b/src/vstest.console/Processors/ListFullyQualifiedTestsArgumentProcessor.cs @@ -215,7 +215,7 @@ public ArgumentProcessorResult Execute() var runSettings = this.runSettingsManager.ActiveRunSettings.SettingsXml; - var success = this.testRequestManager.DiscoverTests( + this.testRequestManager.DiscoverTests( new DiscoveryRequestPayload { Sources = this.commandLineOptions.Sources, RunSettings = runSettings }, this.discoveryEventsRegistrar, Constants.DefaultProtocolConfig); @@ -226,7 +226,7 @@ public ArgumentProcessorResult Execute() } File.WriteAllLines(this.commandLineOptions.ListTestsTargetPath, this.discoveredTests); - return success ? ArgumentProcessorResult.Success : ArgumentProcessorResult.Fail; + return ArgumentProcessorResult.Success; } #endregion diff --git a/src/vstest.console/Processors/ListTestsArgumentProcessor.cs b/src/vstest.console/Processors/ListTestsArgumentProcessor.cs index 4ad11cfbfb..ee80b07bfa 100644 --- a/src/vstest.console/Processors/ListTestsArgumentProcessor.cs +++ b/src/vstest.console/Processors/ListTestsArgumentProcessor.cs @@ -214,11 +214,11 @@ public ArgumentProcessorResult Execute() var runSettings = this.runSettingsManager.ActiveRunSettings.SettingsXml; - var success = this.testRequestManager.DiscoverTests( + this.testRequestManager.DiscoverTests( new DiscoveryRequestPayload() { Sources = this.commandLineOptions.Sources, RunSettings = runSettings }, this.discoveryEventsRegistrar, Constants.DefaultProtocolConfig); - return success ? ArgumentProcessorResult.Success : ArgumentProcessorResult.Fail; + return ArgumentProcessorResult.Success; } #endregion diff --git a/src/vstest.console/Processors/RunSpecificTestsArgumentProcessor.cs b/src/vstest.console/Processors/RunSpecificTestsArgumentProcessor.cs index 97780cad67..8b69359dbf 100644 --- a/src/vstest.console/Processors/RunSpecificTestsArgumentProcessor.cs +++ b/src/vstest.console/Processors/RunSpecificTestsArgumentProcessor.cs @@ -12,8 +12,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers; - using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities; - using Microsoft.VisualStudio.TestPlatform.CommandLineUtilities; using Microsoft.VisualStudio.TestPlatform.Common; using Microsoft.VisualStudio.TestPlatform.Common.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel; @@ -210,17 +208,15 @@ public ArgumentProcessorResult Execute() throw new CommandLineException(string.Format(CultureInfo.CurrentUICulture, CommandLineResources.InvalidTestCaseFilterValueForSpecificTests)); } - bool result = false; - this.effectiveRunSettings = this.runSettingsManager.ActiveRunSettings.SettingsXml; // Discover tests from sources and filter on every discovery reported. - result = this.DiscoverTestsAndSelectSpecified(this.commandLineOptions.Sources); + this.DiscoverTestsAndSelectSpecified(this.commandLineOptions.Sources); // Now that tests are discovered and filtered, we run only those selected tests. - result = result && this.ExecuteSelectedTests(); + this.ExecuteSelectedTests(); - return result ? ArgumentProcessorResult.Success : ArgumentProcessorResult.Fail; + return ArgumentProcessorResult.Success; } #endregion @@ -231,7 +227,7 @@ public ArgumentProcessorResult Execute() /// Discovers tests from the given sources and selects only specified tests. /// /// Test source assemblies paths. - private bool DiscoverTestsAndSelectSpecified(IEnumerable sources) + private void DiscoverTestsAndSelectSpecified(IEnumerable sources) { this.output.WriteLine(CommandLineResources.StartingDiscovery, OutputLevel.Information); if (!string.IsNullOrEmpty(EqtTrace.LogFile)) @@ -239,16 +235,15 @@ private bool DiscoverTestsAndSelectSpecified(IEnumerable sources) this.output.Information(false, CommandLineResources.VstestDiagLogOutputPath, EqtTrace.LogFile); } - return this.testRequestManager.DiscoverTests( + this.testRequestManager.DiscoverTests( new DiscoveryRequestPayload() { Sources = sources, RunSettings = this.effectiveRunSettings }, this.discoveryEventsRegistrar, Constants.DefaultProtocolConfig); } /// /// Executes the selected tests /// - private bool ExecuteSelectedTests() + private void ExecuteSelectedTests() { - bool result = true; if (this.selectedTestCases.Count > 0) { if (this.undiscoveredFilters.Count() != 0) @@ -263,7 +258,7 @@ private bool ExecuteSelectedTests() EqtTrace.Verbose("RunSpecificTestsArgumentProcessor:Execute: Test run is queued."); var runRequestPayload = new TestRunRequestPayload() { TestCases = this.selectedTestCases.ToList(), RunSettings = this.effectiveRunSettings, KeepAlive = keepAlive, TestPlatformOptions = new TestPlatformOptions() { TestCaseFilter = this.commandLineOptions.TestCaseFilterValue }}; - result &= this.testRequestManager.RunTests(runRequestPayload, null, null, Constants.DefaultProtocolConfig); + this.testRequestManager.RunTests(runRequestPayload, null, null, Constants.DefaultProtocolConfig); } else { @@ -286,8 +281,6 @@ private bool ExecuteSelectedTests() this.output.Warning(false, warningMessage); } - - return result; } /// diff --git a/src/vstest.console/Processors/RunTestsArgumentProcessor.cs b/src/vstest.console/Processors/RunTestsArgumentProcessor.cs index 8487854480..265b230568 100644 --- a/src/vstest.console/Processors/RunTestsArgumentProcessor.cs +++ b/src/vstest.console/Processors/RunTestsArgumentProcessor.cs @@ -11,7 +11,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers; - using Microsoft.VisualStudio.TestPlatform.CommandLineUtilities; using Microsoft.VisualStudio.TestPlatform.Common; using Microsoft.VisualStudio.TestPlatform.Common.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel; @@ -168,16 +167,15 @@ public ArgumentProcessorResult Execute() this.output.Information(false, CommandLineResources.VstestDiagLogOutputPath, EqtTrace.LogFile); } - var success = true; if (this.commandLineOptions.Sources.Any()) { - success = this.RunTests(this.commandLineOptions.Sources); + this.RunTests(this.commandLineOptions.Sources); } - return success ? ArgumentProcessorResult.Success : ArgumentProcessorResult.Fail; + return ArgumentProcessorResult.Success; } - private bool RunTests(IEnumerable sources) + private void RunTests(IEnumerable sources) { // create/start test run if (EqtTrace.IsInfoEnabled) @@ -197,14 +195,12 @@ private bool RunTests(IEnumerable sources) var keepAlive = false; var runRequestPayload = new TestRunRequestPayload() { Sources = this.commandLineOptions.Sources.ToList(), RunSettings = runSettings, KeepAlive = keepAlive, TestPlatformOptions= new TestPlatformOptions() { TestCaseFilter = this.commandLineOptions.TestCaseFilterValue } }; - var result = this.testRequestManager.RunTests(runRequestPayload, null, this.testRunEventsRegistrar, Constants.DefaultProtocolConfig); + this.testRequestManager.RunTests(runRequestPayload, null, this.testRunEventsRegistrar, Constants.DefaultProtocolConfig); if (EqtTrace.IsInfoEnabled) { EqtTrace.Info("RunTestsArgumentProcessor:Execute: Test run is completed."); } - - return result; } private class TestRunRequestEventsRegistrar : ITestRunEventsRegistrar diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index 9d6295b13e..3ecbeae363 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -134,11 +134,10 @@ public void ResetOptions() /// EventHandler for discovered tests /// Protocol related information /// True, if successful - public bool DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscoveryEventsRegistrar discoveryEventsRegistrar, ProtocolConfig protocolConfig) + public void DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscoveryEventsRegistrar discoveryEventsRegistrar, ProtocolConfig protocolConfig) { EqtTrace.Info("TestRequestManager.DiscoverTests: Discovery tests started."); - bool success = false; var runsettings = discoveryPayload.RunSettings; if (discoveryPayload.TestPlatformOptions != null) @@ -180,8 +179,6 @@ public bool DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscove discoveryRequest.DiscoverAsync(); discoveryRequest.WaitForCompletion(); - - success = true; } finally @@ -190,28 +187,14 @@ public bool DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscove } } } - catch (Exception ex) + finally { - if (ex is TestPlatformException || - ex is SettingsException || - ex is InvalidOperationException) - { - ConsoleLogger.RaiseTestRunError(null, ex); - success = false; - } - else - { - throw; - } - } - - EqtTrace.Info("TestRequestManager.DiscoverTests: Discovery tests completed, successful: {0}.", success); - this.testPlatformEventSource.DiscoveryRequestStop(); - - // Posts the Discovery Complete event. - this.metricsPublisher.Result.PublishMetrics(TelemetryDataConstants.TestDiscoveryCompleteEvent, requestData.MetricsCollection.Metrics); + EqtTrace.Info("TestRequestManager.DiscoverTests: Discovery tests completed."); + this.testPlatformEventSource.DiscoveryRequestStop(); - return success; + // Posts the Discovery Complete event. + this.metricsPublisher.Result.PublishMetrics(TelemetryDataConstants.TestDiscoveryCompleteEvent, requestData.MetricsCollection.Metrics); + } } /// @@ -222,7 +205,7 @@ ex is SettingsException || /// event registrar for run events /// Protocol related information /// True, if successful - public bool RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLauncher testHostLauncher, ITestRunEventsRegistrar testRunEventsRegistrar, ProtocolConfig protocolConfig) + public void RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLauncher testHostLauncher, ITestRunEventsRegistrar testRunEventsRegistrar, ProtocolConfig protocolConfig) { EqtTrace.Info("TestRequestManager.RunTests: run tests started."); @@ -291,14 +274,19 @@ public bool RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLaunc testHostLauncher); } - var success = this.RunTests(requestData, runCriteria, testRunEventsRegistrar); - EqtTrace.Info("TestRequestManager.RunTests: run tests completed, sucessful: {0}.", success); - this.testPlatformEventSource.ExecutionRequestStop(); - - // Post the run complete event - this.metricsPublisher.Result.PublishMetrics(TelemetryDataConstants.TestExecutionCompleteEvent, requestData.MetricsCollection.Metrics); + // Run tests + try + { + this.RunTests(requestData, runCriteria, testRunEventsRegistrar); + EqtTrace.Info("TestRequestManager.RunTests: run tests completed."); + } + finally + { + this.testPlatformEventSource.ExecutionRequestStop(); - return success; + // Post the run complete event + this.metricsPublisher.Result.PublishMetrics(TelemetryDataConstants.TestExecutionCompleteEvent, requestData.MetricsCollection.Metrics); + } } /// @@ -393,7 +381,7 @@ private bool UpdateRunSettingsIfRequired(string runsettingsXml, List sou if (!string.IsNullOrEmpty(incompatibleSettingWarning)) { EqtTrace.Info(incompatibleSettingWarning); - ConsoleLogger.RaiseTestRunWarning(this.testRunResultAggregator, incompatibleSettingWarning); + ConsoleLogger.RaiseTestRunWarning(incompatibleSettingWarning); } if (EqtTrace.IsInfoEnabled) @@ -511,7 +499,7 @@ private bool UpdateConsoleLoggerIfExists(XmlDocument document, string runsetting return false; } - private bool RunTests(IRequestData requestData, TestRunCriteria testRunCriteria, ITestRunEventsRegistrar testRunEventsRegistrar) + private void RunTests(IRequestData requestData, TestRunCriteria testRunCriteria, ITestRunEventsRegistrar testRunEventsRegistrar) { // Make sure to run the run request inside a lock as the below section is not thread-safe // TranslationLayer can process faster as it directly gets the raw unserialized messages whereas @@ -519,8 +507,6 @@ private bool RunTests(IRequestData requestData, TestRunCriteria testRunCriteria, // While this section is cleaning up, TranslationLayer can trigger run causing multiple threads to run the below section at the same time lock (syncobject) { - bool success = true; - try { this.currentTestRunRequest = this.testPlatform.CreateTestRunRequest(requestData, testRunCriteria); @@ -539,17 +525,8 @@ private bool RunTests(IRequestData requestData, TestRunCriteria testRunCriteria, catch (Exception ex) { EqtTrace.Error("TestRequestManager.RunTests: failed to run tests: {0}", ex); - if (ex is TestPlatformException || - ex is SettingsException || - ex is InvalidOperationException) - { - ConsoleLogger.RaiseTestRunError(this.testRunResultAggregator, ex); - success = false; - } - else - { - throw; - } + testRunResultAggregator.MarkTestRunFailed(); + throw; } finally { @@ -562,8 +539,6 @@ ex is SettingsException || this.currentTestRunRequest = null; } } - - return success; } } diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs index fc58022b50..c2cb902ce5 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs @@ -336,6 +336,30 @@ public void DesignModeClientConnectShouldSendTestMessageAndDiscoverCompleteOnExc this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.DiscoveryComplete, It.IsAny()), Times.Once()); } + [TestMethod] + public void DesignModeClientConnectShouldSendTestMessageAndDiscoverCompleteOnTestPlatformExceptionInDiscovery() + { + var payload = new DiscoveryRequestPayload(); + var startDiscovery = new Message { MessageType = MessageType.StartDiscovery, Payload = JToken.FromObject(payload) }; + this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny())).Returns(true); + this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(startDiscovery); + this.mockCommunicationManager + .Setup(cm => cm.SendMessage(MessageType.DiscoveryComplete, It.IsAny())) + .Callback(() => complateEvent.Set()); + this.mockTestRequestManager.Setup( + rm => rm.DiscoverTests( + It.IsAny(), + It.IsAny(), + It.IsAny())) + .Throws(new TestPlatformException("Hello world")); + + this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); + + Assert.IsTrue(this.complateEvent.WaitOne(Timeout), "Discovery not completed."); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.IsAny()), Times.Once()); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.DiscoveryComplete, It.IsAny()), Times.Once()); + } + [TestMethod] public void DesignModeClientConnectShouldSendTestMessageAndExecutionCompleteOnExceptionInTestRun() { @@ -360,6 +384,30 @@ public void DesignModeClientConnectShouldSendTestMessageAndExecutionCompleteOnEx this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.ExecutionComplete, It.IsAny()), Times.Once()); } + [TestMethod] + public void DesignModeClientConnectShouldSendTestMessageAndExecutionCompleteOnTestPlatformExceptionInTestRun() + { + var payload = new TestRunRequestPayload(); + var testRunAll = new Message { MessageType = MessageType.TestRunAllSourcesWithDefaultHost, Payload = JToken.FromObject(payload) }; + this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny())).Returns(true); + this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(testRunAll); + this.mockCommunicationManager + .Setup(cm => cm.SendMessage(MessageType.ExecutionComplete, It.IsAny())) + .Callback(() => this.complateEvent.Set()); + this.mockTestRequestManager.Setup( + rm => rm.RunTests( + It.IsAny(), + null, + It.IsAny(), + It.IsAny())).Throws(new TestPlatformException("Hello world")); + + this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); + + Assert.IsTrue(this.complateEvent.WaitOne(Timeout), "Execution not completed."); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.IsAny()), Times.Once()); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.ExecutionComplete, It.IsAny()), Times.Once()); + } + private class TestableDesignModeClient : DesignModeClient { internal TestableDesignModeClient( diff --git a/test/vstest.console.UnitTests/ExecutorUnitTests.cs b/test/vstest.console.UnitTests/ExecutorUnitTests.cs index 9dc1abaa76..d419f56b81 100644 --- a/test/vstest.console.UnitTests/ExecutorUnitTests.cs +++ b/test/vstest.console.UnitTests/ExecutorUnitTests.cs @@ -147,6 +147,81 @@ public void ExecuteShouldExitWithErrorOnResponseFileException() Assert.AreEqual(1, exitCode, "Response File Exception execution should exit with error."); } + [TestMethod] + public void ExecuteShouldNotThrowSettingsExceptionButLogOutput() + { + var activeRunSetting = RunSettingsManager.Instance.ActiveRunSettings; + var runSettingsFile = Path.Combine(Path.GetTempPath(), "ExecutorShouldShowRightErrorMessage.runsettings"); + + try + { + if (File.Exists(runSettingsFile)) + { + File.Delete(runSettingsFile); + } + + var fileContents = @" + + + + + + "; + + File.WriteAllText(runSettingsFile, fileContents); + + string[] args = { "/settings:" + runSettingsFile }; + var mockOutput = new MockOutput(); + + var exitCode = new Executor(mockOutput, this.mockTestPlatformEventSource.Object).Execute(args); + + var result = mockOutput.Messages.Any(o => o.Level == OutputLevel.Error && o.Message.Contains("Invalid settings 'Logger'. Unexpected XmlAttribute: 'invalidName'.")); + Assert.IsTrue(result, "expecting error message : Invalid settings 'Logger'.Unexpected XmlAttribute: 'invalidName'."); + } + finally + { + File.Delete(runSettingsFile); + RunSettingsManager.Instance.SetActiveRunSettings(activeRunSetting); + } + } + + [TestMethod] + public void ExecuteShouldReturnNonZeroExitCodeIfSettingsException() + { + var activeRunSetting = RunSettingsManager.Instance.ActiveRunSettings; + var runSettingsFile = Path.Combine(Path.GetTempPath(), "ExecutorShouldShowRightErrorMessage.runsettings"); + + try + { + if (File.Exists(runSettingsFile)) + { + File.Delete(runSettingsFile); + } + + var fileContents = @" + + + + + + "; + + File.WriteAllText(runSettingsFile, fileContents); + + string[] args = { "/settings:" + runSettingsFile }; + var mockOutput = new MockOutput(); + + var exitCode = new Executor(mockOutput, this.mockTestPlatformEventSource.Object).Execute(args); + + Assert.AreEqual(1, exitCode, "Exit code should be one because it throws exception"); + } + finally + { + File.Delete(runSettingsFile); + RunSettingsManager.Instance.SetActiveRunSettings(activeRunSetting); + } + } + [TestMethod] public void ExecutorShouldShowRightErrorMessage() { diff --git a/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs b/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs index 0f5004f27d..7cddd38768 100644 --- a/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs +++ b/test/vstest.console.UnitTests/Internal/ConsoleLoggerTests.cs @@ -255,6 +255,7 @@ public void DetailedVerbosityShowStdOutMessagesForPassedTests() // Act. Raise an event on mock object loggerEvents.RaiseTestResult(new TestResultEventArgs(testresult)); + loggerEvents.WaitForEventCompletion(); // Verify this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.StdOutMessagesBanner, OutputLevel.Information), Times.Once()); @@ -382,10 +383,6 @@ public void TestResultHandlerShouldNotShowStdOutMessagesBannerIfStdOutIsEmpty() [TestMethod] public void TestResultHandlerShouldShowStdErrMessagesBannerIfStdErrIsNotEmpty() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -402,9 +399,7 @@ public void TestResultHandlerShouldShowStdErrMessagesBannerIfStdErrIsNotEmpty() testresult.Messages.Add(testResultMessage); loggerEvents.RaiseTestResult(new TestResultEventArgs(testresult)); - - // Added this for synchronization - SpinWait.SpinUntil(() => count == 2, 300); + loggerEvents.WaitForEventCompletion(); this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.StdErrMessagesBanner, OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Once()); @@ -437,10 +432,6 @@ public void TestResultHandlerShouldNotShowStdErrMessagesBannerIfStdErrIsEmpty() [TestMethod] public void TestResultHandlerShouldShowAdditionalInfoBannerIfAdditionalInfoIsNotEmpty() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -457,9 +448,7 @@ public void TestResultHandlerShouldShowAdditionalInfoBannerIfAdditionalInfoIsNot testresult.Messages.Add(testResultMessage); loggerEvents.RaiseTestResult(new TestResultEventArgs(testresult)); - - // Added this for synchronization - SpinWait.SpinUntil(() => count == 2, 300); + loggerEvents.WaitForEventCompletion(); this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.AddnlInfoMessagesBanner, OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Once()); @@ -494,10 +483,6 @@ public void TestResultHandlerShouldNotShowAdditionalInfoBannerIfAdditionalInfoIs [TestMethod] public void TestResultHandlerShouldWriteToConsoleShouldShowPassedTestsForNormalVebosity() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -508,9 +493,7 @@ public void TestResultHandlerShouldWriteToConsoleShouldShowPassedTestsForNormalV { loggerEvents.RaiseTestResult(new TestResultEventArgs(testResult)); } - - // Added this for synchronization - SpinWait.SpinUntil(() => count == 5, 300); + loggerEvents.WaitForEventCompletion(); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.PassedTestIndicator, "TestName"), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.FailedTestIndicator, "TestName"), OutputLevel.Information), Times.Once()); @@ -521,10 +504,6 @@ public void TestResultHandlerShouldWriteToConsoleShouldShowPassedTestsForNormalV [TestMethod] public void TestResultHandlerShouldNotShowNotStdOutMsgOfPassedTestIfVerbosityIsNormal() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -541,9 +520,7 @@ public void TestResultHandlerShouldNotShowNotStdOutMsgOfPassedTestIfVerbosityIsN testresult.Messages.Add(testResultMessage); loggerEvents.RaiseTestResult(new TestResultEventArgs(testresult)); - - // Added this for synchronization - SpinWait.SpinUntil(() => count == 2, 300); + loggerEvents.WaitForEventCompletion(); this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.StdOutMessagesBanner, OutputLevel.Information), Times.Never()); this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Never()); @@ -552,10 +529,6 @@ public void TestResultHandlerShouldNotShowNotStdOutMsgOfPassedTestIfVerbosityIsN [TestMethod] public void TestResultHandlerShouldNotShowDbgTrcMsg() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -572,9 +545,7 @@ public void TestResultHandlerShouldNotShowDbgTrcMsg() testresult.Messages.Add(testResultMessage); loggerEvents.RaiseTestResult(new TestResultEventArgs(testresult)); - - // Added this for synchronization - SpinWait.SpinUntil(() => count == 2, 300); + loggerEvents.WaitForEventCompletion(); this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.DbgTrcMessagesBanner, OutputLevel.Information), Times.Never()); this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Never()); @@ -583,10 +554,6 @@ public void TestResultHandlerShouldNotShowDbgTrcMsg() [TestMethod] public void TestResultHandlerShouldWriteToConsoleButSkipPassedTestsForMinimalVerbosity() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -597,9 +564,8 @@ public void TestResultHandlerShouldWriteToConsoleButSkipPassedTestsForMinimalVer { loggerEvents.RaiseTestResult(new TestResultEventArgs(testResult)); } + loggerEvents.WaitForEventCompletion(); - // Added this for synchronization - SpinWait.SpinUntil(() => count == 4, 300); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.PassedTestIndicator, "TestName"), OutputLevel.Information), Times.Never); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.FailedTestIndicator, "TestName"), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.SkippedTestIndicator, "TestName"), OutputLevel.Warning), Times.Once()); @@ -629,10 +595,6 @@ public void TestResultHandlerShouldWriteToNoTestResultForQuietVerbosity() [TestMethod] public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsPass() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -645,9 +607,6 @@ public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsPass() } loggerEvents.CompleteTestRun(null, false, false, null, null, new TimeSpan(1, 0, 0, 0)); - // Added this for synchronization - SpinWait.SpinUntil(() => count == 2, 300); - this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummary, 1, 1, 0, 0), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.TestRunSuccessful, OutputLevel.Information), Times.Once()); } @@ -655,10 +614,6 @@ public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsPass() [TestMethod] public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsFail() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -671,9 +626,6 @@ public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsFail() } loggerEvents.CompleteTestRun(null, false, false, null, null, new TimeSpan(1, 0, 0, 0)); - // Added this for synchronization - SpinWait.SpinUntil(() => count == 2, 300); - this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummary, 1, 0, 1, 0), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.TestRunFailed, OutputLevel.Error), Times.Once()); } @@ -681,10 +633,6 @@ public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsFail() [TestMethod] public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsCanceled() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary @@ -699,9 +647,6 @@ public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsCanceled() } loggerEvents.CompleteTestRun(null, true, false, null, null, new TimeSpan(1, 0, 0, 0)); - // Added this for synchronization - SpinWait.SpinUntil(() => count == 2, 300); - this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryForCanceledOrAbortedRun, 0, 1, 0), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.TestRunCanceled, OutputLevel.Error), Times.Once()); } @@ -709,10 +654,6 @@ public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsCanceled() [TestMethod] public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsCanceledWithoutRunningAnyTest() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -721,19 +662,12 @@ public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsCanceledWithoutRunn loggerEvents.CompleteTestRun(null, true, false, null, null, new TimeSpan(1, 0, 0, 0)); - // Added this for synchronization - SpinWait.SpinUntil(() => count == 1, 300); - this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.TestRunCanceled, OutputLevel.Error), Times.Once()); } [TestMethod] public void TestRunCompleteHandlerShouldNotWriteTolatTestToConsoleIfTestsCanceled() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -746,9 +680,6 @@ public void TestRunCompleteHandlerShouldNotWriteTolatTestToConsoleIfTestsCancele } loggerEvents.CompleteTestRun(null, true, false, null, null, new TimeSpan(1, 0, 0, 0)); - // Added this for synchronization - SpinWait.SpinUntil(() => count == 2, 300); - this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryForCanceledOrAbortedRun, 0, 1, 0), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.TestRunCanceled, OutputLevel.Error), Times.Once()); } @@ -756,10 +687,6 @@ public void TestRunCompleteHandlerShouldNotWriteTolatTestToConsoleIfTestsCancele [TestMethod] public void TestRunCompleteHandlerShouldNotWriteTolatTestToConsoleIfTestsAborted() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -772,9 +699,6 @@ public void TestRunCompleteHandlerShouldNotWriteTolatTestToConsoleIfTestsAborted } loggerEvents.CompleteTestRun(null, false, true, null, null, new TimeSpan(1, 0, 0, 0)); - // Added this for synchronization - SpinWait.SpinUntil(() => count == 2, 300); - this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryForCanceledOrAbortedRun, 0, 1, 0), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.TestRunAborted, OutputLevel.Error), Times.Once()); } @@ -782,10 +706,6 @@ public void TestRunCompleteHandlerShouldNotWriteTolatTestToConsoleIfTestsAborted [TestMethod] public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsAborted() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -798,9 +718,6 @@ public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsAborted() } loggerEvents.CompleteTestRun(null, false, true, null, null, new TimeSpan(1, 0, 0, 0)); - // Added this for synchronization - SpinWait.SpinUntil(() => count == 2, 300); - this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryForCanceledOrAbortedRun, 0, 1, 0), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.TestRunAborted, OutputLevel.Error), Times.Once()); } @@ -808,10 +725,6 @@ public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsAborted() [TestMethod] public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsAbortedWithoutRunningAnyTest() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -820,19 +733,12 @@ public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsAbortedWithoutRunni loggerEvents.CompleteTestRun(null, false, true, null, null, new TimeSpan(1, 0, 0, 0)); - // Added this for synchronization - SpinWait.SpinUntil(() => count == 1, 300); - this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.TestRunAborted, OutputLevel.Error), Times.Once()); } [TestMethod] public void PrintTimeHandlerShouldPrintElapsedTimeOnConsole() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -848,9 +754,6 @@ public void PrintTimeHandlerShouldPrintElapsedTimeOnConsole() loggerEvents.CompleteTestRun(null, false, false, null, null, new TimeSpan(0, 0, 1, 0)); loggerEvents.CompleteTestRun(null, false, false, null, null, new TimeSpan(0, 0, 0, 1)); - // Added this for synchronization - SpinWait.SpinUntil(() => count == 4, 300); - // Verify PrintTimeSpan with different formats this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.ExecutionTimeFormatString, 1, CommandLineResources.Days), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.ExecutionTimeFormatString, 1, CommandLineResources.Hours), OutputLevel.Information), Times.Once()); @@ -861,10 +764,6 @@ public void PrintTimeHandlerShouldPrintElapsedTimeOnConsole() [TestMethod] public void DisplayFullInformationShouldWriteErrorMessageAndStackTraceToConsole() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -878,9 +777,7 @@ public void DisplayFullInformationShouldWriteErrorMessageAndStackTraceToConsole( { loggerEvents.RaiseTestResult(new TestResultEventArgs(testResult)); } - - // Added this for synchronization - SpinWait.SpinUntil(() => count == 4, 300); + loggerEvents.WaitForEventCompletion(); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0}", " ErrorMessage"), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0}", "ErrorStackTrace"), OutputLevel.Information), Times.Once()); @@ -891,10 +788,6 @@ public void DisplayFullInformationShouldWriteErrorMessageAndStackTraceToConsole( [TestMethod] public void DisplayFullInformationShouldWriteStdMessageWithNewLine() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -908,9 +801,7 @@ public void DisplayFullInformationShouldWriteStdMessageWithNewLine() { loggerEvents.RaiseTestResult(new TestResultEventArgs(testResult)); } - - // Added this for synchronization - SpinWait.SpinUntil(() => count == 4, 300); + loggerEvents.WaitForEventCompletion(); this.mockOutput.Verify(o => o.WriteLine("Passed TestName", OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(" Hello", OutputLevel.Information), Times.Once()); @@ -920,10 +811,6 @@ public void DisplayFullInformationShouldWriteStdMessageWithNewLine() [TestMethod] public void GetTestMessagesShouldWriteMessageAndStackTraceToConsole() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -940,9 +827,7 @@ public void GetTestMessagesShouldWriteMessageAndStackTraceToConsole() { loggerEvents.RaiseTestResult(new TestResultEventArgs(testResult)); } - - // Added this for synchronization - SpinWait.SpinUntil(() => count == 6, 300); + loggerEvents.WaitForEventCompletion(); this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.StdOutMessagesBanner, OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(" StandardOutCategory", OutputLevel.Information), Times.Once()); @@ -957,10 +842,6 @@ public void GetTestMessagesShouldWriteMessageAndStackTraceToConsole() [TestMethod] public void AttachmentInformationShouldBeWrittenToConsoleIfAttachmentsArePresent() { - var count = 0; - this.mockOutput.Setup(o => o.WriteLine(It.IsAny(), It.IsAny())).Callback( - (s, o) => { count++; }); - var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary(); @@ -978,9 +859,6 @@ public void AttachmentInformationShouldBeWrittenToConsoleIfAttachmentsArePresent }; loggerEvents.CompleteTestRun(null, false, false, null, new Collection(attachmentSetList), new TimeSpan(1, 0, 0, 0)); - // Added this for synchronization - SpinWait.SpinUntil(() => count == 2, 300); - this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.AttachmentOutputFormat, uriDataAttachment.Uri.LocalPath), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.AttachmentOutputFormat, uriDataAttachment1.Uri.LocalPath), OutputLevel.Information), Times.Once()); } diff --git a/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs index 64d76affc3..fb5f8b24b4 100644 --- a/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/ListFullyQualifiedTestsArgumentProcessorTests.cs @@ -7,31 +7,24 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using System.Collections.Generic; using System.IO; using System.Linq; - using System.Threading.Tasks; using System.Runtime.Versioning; - - using Common.Logging; + using System.Threading.Tasks; using CoreUtilities.Tracing.Interfaces; using Microsoft.VisualStudio.TestPlatform.Client; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; - using Microsoft.VisualStudio.TestPlatform.CommandLineUtilities; using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors; using Microsoft.VisualStudio.TestPlatform.CommandLine.Publisher; + using Microsoft.VisualStudio.TestPlatform.CommandLineUtilities; using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; - using Moq; - using ObjectModel; using ObjectModel.Client; - using TestPlatform.Utilities; - using TestPlatformHelpers; - using vstest.console.UnitTests.Processors; // @@ -145,7 +138,7 @@ public void ExecutorExecuteForNoSourcesShouldReturnFail() } [TestMethod] - public void ExecutorExecuteShouldCatchTestPlatformExceptionAndReturnFail() + public void ExecutorExecuteShouldThrowTestPlatformException() { var mockTestPlatform = new Mock(); var mockDiscoveryRequest = new Mock(); @@ -159,12 +152,11 @@ public void ExecutorExecuteShouldCatchTestPlatformExceptionAndReturnFail() var executor = GetExecutor(testRequestManager, null); - var argumentProcessorResult = executor.Execute(); - Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult); + Assert.ThrowsException(() => executor.Execute()); } [TestMethod] - public void ExecutorExecuteShouldCatchSettingsExceptionAndReturnFail() + public void ExecutorExecuteShouldThrowSettingsException() { var mockTestPlatform = new Mock(); var mockDiscoveryRequest = new Mock(); @@ -177,12 +169,11 @@ public void ExecutorExecuteShouldCatchSettingsExceptionAndReturnFail() var listTestsArgumentExecutor = GetExecutor(testRequestManager, null); - var argumentProcessorResult = listTestsArgumentExecutor.Execute(); - Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult); + Assert.ThrowsException(() => listTestsArgumentExecutor.Execute()); } [TestMethod] - public void ExecutorExecuteShouldCatchInvalidOperationExceptionAndReturnFail() + public void ExecutorExecuteShouldThrowInvalidOperationException() { var mockTestPlatform = new Mock(); var mockDiscoveryRequest = new Mock(); @@ -197,8 +188,7 @@ public void ExecutorExecuteShouldCatchInvalidOperationExceptionAndReturnFail() var listTestsArgumentExecutor = GetExecutor(testRequestManager, null); - var argumentProcessorResult = listTestsArgumentExecutor.Execute(); - Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult); + Assert.ThrowsException(() => listTestsArgumentExecutor.Execute()); } [TestMethod] diff --git a/test/vstest.console.UnitTests/Processors/ListTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/ListTestsArgumentProcessorTests.cs index 44e494ff4f..b2f3ed41f8 100644 --- a/test/vstest.console.UnitTests/Processors/ListTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/ListTestsArgumentProcessorTests.cs @@ -6,31 +6,24 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using System; using System.Collections.Generic; using System.Linq; - using System.Threading.Tasks; using System.Runtime.Versioning; - - using Common.Logging; + using System.Threading.Tasks; using CoreUtilities.Tracing.Interfaces; using Microsoft.VisualStudio.TestPlatform.Client; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors; - using Microsoft.VisualStudio.TestPlatform.CommandLineUtilities; using Microsoft.VisualStudio.TestPlatform.CommandLine.Publisher; + using Microsoft.VisualStudio.TestPlatform.CommandLineUtilities; using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; - using Moq; - using ObjectModel; using ObjectModel.Client; - using TestPlatform.Utilities; - using TestPlatformHelpers; - using vstest.console.UnitTests.Processors; // @@ -148,7 +141,7 @@ public void ExecutorExecuteForNoSourcesShouldReturnFail() } [TestMethod] - public void ExecutorExecuteShouldCatchTestPlatformExceptionAndReturnFail() + public void ExecutorExecuteShouldThrowTestPlatformException() { var mockTestPlatform = new Mock(); var mockDiscoveryRequest = new Mock(); @@ -161,12 +154,11 @@ public void ExecutorExecuteShouldCatchTestPlatformExceptionAndReturnFail() var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); var executor = GetExecutor(testRequestManager, null); - var argumentProcessorResult = executor.Execute(); - Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult); + Assert.ThrowsException(() => executor.Execute()); } [TestMethod] - public void ExecutorExecuteShouldCatchSettingsExceptionAndReturnFail() + public void ExecutorExecuteShouldThrowSettingsException() { var mockTestPlatform = new Mock(); var mockDiscoveryRequest = new Mock(); @@ -179,12 +171,11 @@ public void ExecutorExecuteShouldCatchSettingsExceptionAndReturnFail() var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); var listTestsArgumentExecutor = GetExecutor(testRequestManager, null); - var argumentProcessorResult = listTestsArgumentExecutor.Execute(); - Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult); + Assert.ThrowsException(() => listTestsArgumentExecutor.Execute()); } [TestMethod] - public void ExecutorExecuteShouldCatchInvalidOperationExceptionAndReturnFail() + public void ExecutorExecuteShouldThrowInvalidOperationException() { var mockTestPlatform = new Mock(); var mockDiscoveryRequest = new Mock(); @@ -197,8 +188,7 @@ public void ExecutorExecuteShouldCatchInvalidOperationExceptionAndReturnFail() var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); var listTestsArgumentExecutor = GetExecutor(testRequestManager, null); - var argumentProcessorResult = listTestsArgumentExecutor.Execute(); - Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult); + Assert.ThrowsException(() => listTestsArgumentExecutor.Execute()); } [TestMethod] diff --git a/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs index 065396bb11..926dfc93ae 100644 --- a/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/RunSpecificTestsArgumentProcessorTests.cs @@ -1,14 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client; namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors { using System; using System.Collections.Generic; - using System.Threading.Tasks; using System.Runtime.Versioning; + using System.Threading.Tasks; using CommandLineUtilities; using CoreUtilities.Tracing.Interfaces; @@ -18,16 +17,13 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors; using Microsoft.VisualStudio.TestPlatform.CommandLine.Publisher; using Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers; - using Microsoft.VisualStudio.TestPlatform.Common.Logging; using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.Utilities; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; - using Moq; - using vstest.console.UnitTests.Processors; [TestClass] @@ -180,7 +176,7 @@ public void ExecutorExecuteForValidSourceWithTestCaseFilterShouldThrowCommandLin } [TestMethod] - public void ExecutorExecuteShouldCatchTestPlatformExceptionThrownDuringDiscoveryAndReturnFail() + public void ExecutorExecuteShouldThrowTestPlatformExceptionThrownDuringDiscovery() { var mockTestPlatform = new Mock(); var mockTestRunRequest = new Mock(); @@ -194,12 +190,11 @@ public void ExecutorExecuteShouldCatchTestPlatformExceptionThrownDuringDiscovery var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); var executor = GetExecutor(testRequestManager); - ArgumentProcessorResult argumentProcessorResult = executor.Execute(); - Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult); + Assert.ThrowsException(() => executor.Execute()); } [TestMethod] - public void ExecutorExecuteShouldCatchInvalidOperationExceptionThrownDuringDiscoveryAndReturnFail() + public void ExecutorExecuteShouldThrowInvalidOperationExceptionThrownDuringDiscovery() { var mockTestPlatform = new Mock(); var mockTestRunRequest = new Mock(); @@ -213,12 +208,11 @@ public void ExecutorExecuteShouldCatchInvalidOperationExceptionThrownDuringDisco var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); var executor = GetExecutor(testRequestManager); - ArgumentProcessorResult argumentProcessorResult = executor.Execute(); - Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult); + Assert.ThrowsException(() => executor.Execute()); } [TestMethod] - public void ExecutorExecuteShouldCatchSettingsExceptionThrownDuringDiscoveryAndReturnFail() + public void ExecutorExecuteShouldThrowSettingsExceptionThrownDuringDiscovery() { var mockTestPlatform = new Mock(); var mockTestRunRequest = new Mock(); @@ -232,12 +226,11 @@ public void ExecutorExecuteShouldCatchSettingsExceptionThrownDuringDiscoveryAndR var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); var executor = GetExecutor(testRequestManager); - ArgumentProcessorResult argumentProcessorResult = executor.Execute(); - Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult); + Assert.ThrowsException(() => executor.Execute()); } [TestMethod] - public void ExecutorExecuteShouldCatchTestPlatformExceptionThrownDuringExecutionAndReturnFail() + public void ExecutorExecuteShouldThrowTestPlatformExceptionThrownDuringExecution() { var mockTestPlatform = new Mock(); var mockTestRunRequest = new Mock(); @@ -258,12 +251,11 @@ public void ExecutorExecuteShouldCatchTestPlatformExceptionThrownDuringExecution executor.Initialize("Test1"); - ArgumentProcessorResult argumentProcessorResult = executor.Execute(); - Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult); + Assert.ThrowsException(() => executor.Execute()); } [TestMethod] - public void ExecutorExecuteShouldCatchSettingsExceptionThrownDuringExecutionAndReturnFail() + public void ExecutorExecuteShouldThrowSettingsExceptionThrownDuringExecution() { var mockTestPlatform = new Mock(); var mockTestRunRequest = new Mock(); @@ -284,12 +276,11 @@ public void ExecutorExecuteShouldCatchSettingsExceptionThrownDuringExecutionAndR executor.Initialize("Test1"); - ArgumentProcessorResult argumentProcessorResult = executor.Execute(); - Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult); + Assert.ThrowsException(() => executor.Execute()); } [TestMethod] - public void ExecutorExecuteShouldCatchInvalidOperationExceptionThrownDuringExecutionAndReturnFail() + public void ExecutorExecuteShouldThrowInvalidOperationExceptionThrownDuringExecution() { var mockTestPlatform = new Mock(); var mockTestRunRequest = new Mock(); @@ -300,7 +291,7 @@ public void ExecutorExecuteShouldCatchInvalidOperationExceptionThrownDuringExecu list.Add(new TestCase("Test2", new Uri("http://FooTestUri2"), "Source2")); mockDiscoveryRequest.Setup(dr => dr.DiscoverAsync()).Raises(dr => dr.OnDiscoveredTests += null, new DiscoveredTestsEventArgs(list)); - mockTestRunRequest.Setup(dr => dr.ExecuteAsync()).Throws(new SettingsException("DummySettingsException")); + mockTestRunRequest.Setup(dr => dr.ExecuteAsync()).Throws(new InvalidOperationException("DummySettingsException")); mockTestPlatform.Setup(tp => tp.CreateTestRunRequest(It.IsAny(), It.IsAny())).Returns(mockTestRunRequest.Object); mockTestPlatform.Setup(tp => tp.CreateDiscoveryRequest(It.IsAny(), It.IsAny())).Returns(mockDiscoveryRequest.Object); @@ -311,8 +302,7 @@ public void ExecutorExecuteShouldCatchInvalidOperationExceptionThrownDuringExecu executor.Initialize("Test1"); - ArgumentProcessorResult argumentProcessorResult = executor.Execute(); - Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult); + Assert.ThrowsException(() => executor.Execute()); } [TestMethod] diff --git a/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs index 0a8fa1f9b4..1dc42adce9 100644 --- a/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/RunTestsArgumentProcessorTests.cs @@ -9,8 +9,8 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using System.Collections.Generic; using System.IO; using System.Reflection; - using System.Threading.Tasks; using System.Runtime.Versioning; + using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.Client; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; @@ -19,7 +19,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using Microsoft.VisualStudio.TestPlatform.CommandLine.Publisher; using Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers; using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework; - using Microsoft.VisualStudio.TestPlatform.Common.Logging; using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel; @@ -28,9 +27,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.UnitTests.Processors using Microsoft.VisualStudio.TestPlatform.Utilities; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; - using Moq; - using vstest.console.UnitTests.Processors; /// @@ -138,7 +135,7 @@ private RunTestsArgumentExecutor GetExecutor(ITestRequestManager testRequestMana } [TestMethod] - public void ExecutorExecuteShouldCatchTestPlatformExceptionAndReturnFail() + public void ExecutorExecuteShouldThrowTestPlatformException() { var mockTestPlatform = new Mock(); var mockTestRunRequest = new Mock(); @@ -150,12 +147,11 @@ public void ExecutorExecuteShouldCatchTestPlatformExceptionAndReturnFail() var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); var executor = GetExecutor(testRequestManager); - ArgumentProcessorResult argumentProcessorResult = executor.Execute(); - Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult); + Assert.ThrowsException(() => executor.Execute()); } [TestMethod] - public void ExecutorExecuteShouldCatchSettingsExceptionAndReturnFail() + public void ExecutorExecuteShouldThrowSettingsException() { var mockTestPlatform = new Mock(); var mockTestRunRequest = new Mock(); @@ -167,12 +163,11 @@ public void ExecutorExecuteShouldCatchSettingsExceptionAndReturnFail() var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); var executor = GetExecutor(testRequestManager); - ArgumentProcessorResult argumentProcessorResult = executor.Execute(); - Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult); + Assert.ThrowsException(() => executor.Execute()); } [TestMethod] - public void ExecutorExecuteShouldCatchInvalidOperationExceptionAndReturnFail() + public void ExecutorExecuteShouldThrowInvalidOperationException() { var mockTestPlatform = new Mock(); var mockTestRunRequest = new Mock(); @@ -184,8 +179,7 @@ public void ExecutorExecuteShouldCatchInvalidOperationExceptionAndReturnFail() var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, mockTestPlatform.Object, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask); var executor = GetExecutor(testRequestManager); - ArgumentProcessorResult argumentProcessorResult = executor.Execute(); - Assert.AreEqual(ArgumentProcessorResult.Fail, argumentProcessorResult); + Assert.ThrowsException(() => executor.Execute()); } [TestMethod] diff --git a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs index 15b7028866..7f57998ce3 100644 --- a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs +++ b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs @@ -167,7 +167,7 @@ public void DiscoverTestsShouldReadTheBatchSizeFromSettingsAndSetItForDiscoveryC actualDiscoveryCriteria = discoveryCriteria; }).Returns(mockDiscoveryRequest.Object); - var success = this.testRequestManager.DiscoverTests(payload, new Mock().Object, this.protocolConfig); + this.testRequestManager.DiscoverTests(payload, new Mock().Object, this.protocolConfig); Assert.AreEqual(15, actualDiscoveryCriteria.FrequencyOfDiscoveredTestsEvent); } @@ -201,9 +201,8 @@ public void DiscoverTestsShouldCallTestPlatformAndSucceed() this.inferHelper, this.mockMetricsPublisherTask); - var success = this.testRequestManager.DiscoverTests(payload, mockDiscoveryRegistrar.Object, this.protocolConfig); + this.testRequestManager.DiscoverTests(payload, mockDiscoveryRegistrar.Object, this.protocolConfig); - Assert.IsTrue(success, "DiscoverTests call must succeed"); Assert.AreEqual(testCaseFilterValue, actualDiscoveryCriteria.TestCaseFilter, "TestCaseFilter must be set"); Assert.AreEqual(createDiscoveryRequestCalled, 1, "CreateDiscoveryRequest must be invoked only once."); @@ -679,7 +678,7 @@ public void DiscoverTestsShouldUpdateFrameworkAndPlatformIfNotSpecifiedInDesignM actualDiscoveryCriteria = discoveryCriteria; }).Returns(mockDiscoveryRequest.Object); - var success = this.testRequestManager.DiscoverTests(payload, new Mock().Object, this.protocolConfig); + this.testRequestManager.DiscoverTests(payload, new Mock().Object, this.protocolConfig); this.mockAssemblyMetadataProvider.Verify(a => a.GetArchitecture(It.IsAny())); this.mockAssemblyMetadataProvider.Verify(a => a.GetFrameWork(It.IsAny())); @@ -716,7 +715,7 @@ public void DiscoverTestsShouldNotUpdateFrameworkAndPlatformIfSpecifiedInDesignM actualDiscoveryCriteria = discoveryCriteria; }).Returns(mockDiscoveryRequest.Object); - var success = this.testRequestManager.DiscoverTests(payload, new Mock().Object, this.protocolConfig); + this.testRequestManager.DiscoverTests(payload, new Mock().Object, this.protocolConfig); this.mockAssemblyMetadataProvider.Verify(a => a.GetArchitecture(It.IsAny()), Times.Never); this.mockAssemblyMetadataProvider.Verify(a => a.GetFrameWork(It.IsAny()), Times.Never); @@ -751,7 +750,7 @@ public void DiscoverTestsShouldUpdateFrameworkAndPlatformInCommandLineScenariosI actualDiscoveryCriteria = discoveryCriteria; }).Returns(mockDiscoveryRequest.Object); - var success = this.testRequestManager.DiscoverTests(payload, new Mock().Object, this.protocolConfig); + this.testRequestManager.DiscoverTests(payload, new Mock().Object, this.protocolConfig); this.mockAssemblyMetadataProvider.Verify(a => a.GetArchitecture(It.IsAny())); this.mockAssemblyMetadataProvider.Verify(a => a.GetFrameWork(It.IsAny())); @@ -789,7 +788,7 @@ public void DiscoverTestsShouldNotUpdateFrameworkAndPlatformInCommandLineScenari actualDiscoveryCriteria = discoveryCriteria; }).Returns(mockDiscoveryRequest.Object); - var success = this.testRequestManager.DiscoverTests(payload, + this.testRequestManager.DiscoverTests(payload, new Mock().Object, this.protocolConfig); this.mockAssemblyMetadataProvider.Verify(a => a.GetArchitecture(It.IsAny()), Times.Once); this.mockAssemblyMetadataProvider.Verify(a => a.GetFrameWork(It.IsAny()), Times.Once); @@ -946,7 +945,7 @@ public void RunTestsShouldReadTheBatchSizeFromSettingsAndSetItForTestRunCriteria actualTestRunCriteria = runCriteria; }).Returns(mockDiscoveryRequest.Object); - var success = this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, this.protocolConfig); + this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, this.protocolConfig); Assert.AreEqual(15, actualTestRunCriteria.FrequencyOfRunStatsChangeEvent); } @@ -1114,9 +1113,7 @@ public void RunTestsWithSourcesShouldCallTestPlatformAndSucceed() this.inferHelper, this.mockMetricsPublisherTask); - var success = this.testRequestManager.RunTests(payload, mockCustomlauncher.Object, mockRunEventsRegistrar.Object, this.protocolConfig); - - Assert.IsTrue(success, "RunTests call must succeed"); + this.testRequestManager.RunTests(payload, mockCustomlauncher.Object, mockRunEventsRegistrar.Object, this.protocolConfig); Assert.AreEqual(testCaseFilterValue, observedCriteria.TestCaseFilter, "TestCaseFilter must be set"); @@ -1234,177 +1231,54 @@ public void RunTestsShouldPublishMetrics() this.mockMetricsPublisher.Verify(mp => mp.PublishMetrics(TelemetryDataConstants.TestExecutionCompleteEvent, It.IsAny>()), Times.Once); } + // TODO: add tests in design mode and executor that they are handling all the exceptions properly including printing inner exception. + [TestMethod] - public void RunTestsIfThrowsTestPlatformExceptionShouldNotThrowOut() + public void RunTestsIfThrowsTestPlatformExceptionShouldThrowOut() { - var payload = new TestRunRequestPayload() - { - Sources = new List() { "a", "b" }, - RunSettings = DefaultRunsettings - }; - - var createRunRequestCalled = 0; - TestRunCriteria observedCriteria = null; - var mockRunRequest = new Mock(); - this.mockTestPlatform.Setup(mt => mt.CreateTestRunRequest(It.IsAny(), It.IsAny())).Callback( - (IRequestData requestData, TestRunCriteria runCriteria) => - { - createRunRequestCalled++; - observedCriteria = runCriteria; - }).Returns(mockRunRequest.Object); - - mockRunRequest.Setup(mr => mr.ExecuteAsync()).Throws(new TestPlatformException("HelloWorld")); - - var mockRunEventsRegistrar = new Mock(); - var mockCustomlauncher = new Mock(); - - var success = this.testRequestManager.RunTests(payload, mockCustomlauncher.Object, mockRunEventsRegistrar.Object, this.protocolConfig); - - Assert.IsFalse(success, "RunTests call must fail due to exception"); + Assert.ThrowsException(() => RunTestsIfThrowsExceptionShouldThrowOut(new TestPlatformException("HelloWorld"))); } [TestMethod] - public void RunTestsIfThrowsSettingsExceptionShouldNotThrowOut() + public void RunTestsIfThrowsSettingsExceptionShouldThrowOut() { - var payload = new TestRunRequestPayload() - { - Sources = new List() { "a", "b" }, - RunSettings = DefaultRunsettings - }; - - var createRunRequestCalled = 0; - TestRunCriteria observedCriteria = null; - var mockRunRequest = new Mock(); - this.mockTestPlatform.Setup(mt => mt.CreateTestRunRequest(It.IsAny(), It.IsAny())).Callback( - (IRequestData requestData, TestRunCriteria runCriteria) => - { - createRunRequestCalled++; - observedCriteria = runCriteria; - }).Returns(mockRunRequest.Object); - - mockRunRequest.Setup(mr => mr.ExecuteAsync()).Throws(new SettingsException("HelloWorld")); - - var mockRunEventsRegistrar = new Mock(); - var mockCustomlauncher = new Mock(); - - var success = this.testRequestManager.RunTests(payload, mockCustomlauncher.Object, mockRunEventsRegistrar.Object, this.protocolConfig); - - Assert.IsFalse(success, "RunTests call must fail due to exception"); + Assert.ThrowsException(() => RunTestsIfThrowsExceptionShouldThrowOut(new SettingsException("HelloWorld"))); } [TestMethod] - public void RunTestsShouldOutputErrorForInvalidOperationException() + public void RunTestsIfThrowsInvalidOperationExceptionShouldThrowOut() { - ConsoleLogger consoleLogger = new ConsoleLogger(mockOutput.Object); - var payload = new TestRunRequestPayload() - { - Sources = new List() { "a.dll", "b.dll" }, - RunSettings = DefaultRunsettings - }; - - TestRunCriteria observedCriteria = null; - var mockRunRequest = new Mock(); - this.mockTestPlatform.Setup(mt => mt.CreateTestRunRequest(It.IsAny(), It.IsAny())).Callback( - (IRequestData requestData, TestRunCriteria runCriteria) => - { - observedCriteria = runCriteria; - }).Returns(mockRunRequest.Object); - - mockRunRequest.Setup(mr => mr.ExecuteAsync()).Throws(new InvalidOperationException("HelloWorld")); - - var mockRunEventsRegistrar = new Mock(); - var mockCustomlauncher = new Mock(); - - var success = this.testRequestManager.RunTests(payload, mockCustomlauncher.Object, mockRunEventsRegistrar.Object, this.protocolConfig); - - Assert.IsFalse(success, "RunTests call must fail due to exception"); - mockOutput.Verify(ot => ot.WriteLine("HelloWorld", OutputLevel.Error)); + Assert.ThrowsException(() => RunTestsIfThrowsExceptionShouldThrowOut(new InvalidOperationException("HelloWorld"))); } [TestMethod] - public void DiscoverTestsShouldOutputErrorForInvalidOperationException() + public void RunTestsIfThrowsExceptionShouldThrowOut() { - ConsoleLogger consoleLogger = new ConsoleLogger(mockOutput.Object); - var payload = new DiscoveryRequestPayload() - { - Sources = new List() { "a.dll", "b.dll" }, - RunSettings = DefaultRunsettings - }; - - DiscoveryCriteria observedCriteria = null; - var mockDiscoveryRequest = new Mock(); - this.mockTestPlatform.Setup(mt => mt.CreateDiscoveryRequest(It.IsAny(), It.IsAny())).Callback( - (IRequestData requestData, DiscoveryCriteria discoveryCriteria) => - { - observedCriteria = discoveryCriteria; - }).Returns(mockDiscoveryRequest.Object); - - mockDiscoveryRequest.Setup(mr => mr.DiscoverAsync()).Throws(new InvalidOperationException("HelloWorld")); - - var mockDiscoveryEventsRegistrar = new Mock(); - var mockCustomlauncher = new Mock(); - - var success = this.testRequestManager.DiscoverTests(payload, mockDiscoveryEventsRegistrar.Object, this.protocolConfig); - - Assert.IsFalse(success, "DiscoverTests call must fail due to exception"); - mockOutput.Verify(ot => ot.WriteLine("HelloWorld", OutputLevel.Error)); + Assert.ThrowsException(() => RunTestsIfThrowsExceptionShouldThrowOut(new NotImplementedException("HelloWorld"))); } [TestMethod] - public void RunTestsIfThrowsInvalidOperationExceptionShouldNotThrowOut() + public void DiscoverTestsIfThrowsTestPlatformExceptionShouldThrowOut() { - var payload = new TestRunRequestPayload() - { - Sources = new List() { "a.dll", "b.dll" }, - RunSettings = DefaultRunsettings - }; - - var createRunRequestCalled = 0; - TestRunCriteria observedCriteria = null; - var mockRunRequest = new Mock(); - this.mockTestPlatform.Setup(mt => mt.CreateTestRunRequest(It.IsAny(), It.IsAny())).Callback( - (IRequestData requestData, TestRunCriteria runCriteria) => - { - createRunRequestCalled++; - observedCriteria = runCriteria; - }).Returns(mockRunRequest.Object); - - mockRunRequest.Setup(mr => mr.ExecuteAsync()).Throws(new InvalidOperationException("HelloWorld")); - - var mockRunEventsRegistrar = new Mock(); - var mockCustomlauncher = new Mock(); - - var success = this.testRequestManager.RunTests(payload, mockCustomlauncher.Object, mockRunEventsRegistrar.Object, this.protocolConfig); - - Assert.IsFalse(success, "RunTests call must fail due to exception"); + Assert.ThrowsException(() => DiscoverTestsIfThrowsExceptionShouldThrowOut(new TestPlatformException("HelloWorld"))); } [TestMethod] - [ExpectedException(typeof(NotImplementedException))] - public void RunTestsIfThrowsExceptionShouldThrowOut() + public void DiscoverTestsIfThrowsSettingsExceptionShouldThrowOut() { - var payload = new TestRunRequestPayload() - { - Sources = new List() { "a", "b" }, - RunSettings = DefaultRunsettings - }; - - var createRunRequestCalled = 0; - TestRunCriteria observedCriteria = null; - var mockRunRequest = new Mock(); - this.mockTestPlatform.Setup(mt => mt.CreateTestRunRequest(It.IsAny(), It.IsAny())).Callback( - (IRequestData requestData, TestRunCriteria runCriteria) => - { - createRunRequestCalled++; - observedCriteria = runCriteria; - }).Returns(mockRunRequest.Object); - - mockRunRequest.Setup(mr => mr.ExecuteAsync()).Throws(new NotImplementedException("HelloWorld")); + Assert.ThrowsException(() => DiscoverTestsIfThrowsExceptionShouldThrowOut(new SettingsException("HelloWorld"))); + } - var mockRunEventsRegistrar = new Mock(); - var mockCustomlauncher = new Mock(); + [TestMethod] + public void DiscoverTestsIfThrowsInvalidOperationExceptionShouldThrowOut() + { + Assert.ThrowsException(() => DiscoverTestsIfThrowsExceptionShouldThrowOut(new InvalidOperationException("HelloWorld"))); + } - this.testRequestManager.RunTests(payload, mockCustomlauncher.Object, mockRunEventsRegistrar.Object, this.protocolConfig); + [TestMethod] + public void DiscoverTestsIfThrowsExceptionShouldThrowOut() + { + Assert.ThrowsException(() => DiscoverTestsIfThrowsExceptionShouldThrowOut(new NotImplementedException("HelloWorld"))); } [DataTestMethod] @@ -1503,7 +1377,7 @@ public void RunTestsShouldShouldUpdateFrameworkAndPlatformIfNotSpecifiedInDesign actualTestRunCriteria = runCriteria; }).Returns(mockTestRunRequest.Object); - var success = this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, this.protocolConfig); + this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, this.protocolConfig); this.mockAssemblyMetadataProvider.Verify(a => a.GetArchitecture(It.IsAny())); this.mockAssemblyMetadataProvider.Verify(a => a.GetFrameWork(It.IsAny())); @@ -1542,7 +1416,7 @@ public void RunTestsShouldNotUpdateFrameworkAndPlatformIfSpecifiedInDesignModeBu actualTestRunCriteria = runCriteria; }).Returns(mockTestRunRequest.Object); - var success = this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, this.protocolConfig); + this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, this.protocolConfig); this.mockAssemblyMetadataProvider.Verify(a => a.GetArchitecture(It.IsAny()), Times.Once); this.mockAssemblyMetadataProvider.Verify(a => a.GetFrameWork(It.IsAny()), Times.Once); @@ -1583,7 +1457,7 @@ public void RunTestsShouldNotUpdatePlatformIfSpecifiedInDesignModeButInferred(st actualTestRunCriteria = runCriteria; }).Returns(mockTestRunRequest.Object); - var success = this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, this.protocolConfig); + this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, this.protocolConfig); this.mockAssemblyMetadataProvider.Verify(a => a.GetArchitecture(It.IsAny()), Times.Once); this.mockAssemblyMetadataProvider.Verify(a => a.GetFrameWork(It.IsAny()), Times.Once); @@ -1618,7 +1492,7 @@ public void RunTestsShouldUpdateFrameworkAndPlatformInCommandLineScenarios() actualTestRunCriteria = runCriteria; }).Returns(mockTestRunRequest.Object); - var success = this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, this.protocolConfig); + this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, this.protocolConfig); this.mockAssemblyMetadataProvider.Verify(a => a.GetArchitecture(It.IsAny())); this.mockAssemblyMetadataProvider.Verify(a => a.GetFrameWork(It.IsAny())); @@ -1656,7 +1530,7 @@ public void RunTestsShouldNotpdateFrameworkAndPlatformInCommandLineScenariosIfSp actualTestRunCriteria = runCriteria; }).Returns(mockTestRunRequest.Object); - var success = this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, this.protocolConfig); + this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, this.protocolConfig); this.mockAssemblyMetadataProvider.Verify(a => a.GetArchitecture(It.IsAny()), Times.Once); this.mockAssemblyMetadataProvider.Verify(a => a.GetFrameWork(It.IsAny()), Times.Once); @@ -1699,7 +1573,7 @@ public void RunTestsWithTestCasesShouldUpdateFrameworkAndPlatformIfNotSpecifiedI actualTestRunCriteria = runCriteria; }).Returns(mockTestRunRequest.Object); - var success = this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, this.protocolConfig); + this.testRequestManager.RunTests(payload, new Mock().Object, new Mock().Object, this.protocolConfig); this.mockAssemblyMetadataProvider.Verify(a => a.GetArchitecture(It.IsAny())); this.mockAssemblyMetadataProvider.Verify(a => a.GetFrameWork(It.IsAny())); @@ -2251,5 +2125,55 @@ private static DiscoveryRequestPayload CreateDiscoveryPayload(string runsettings }; return discoveryPayload; } + + private void RunTestsIfThrowsExceptionShouldThrowOut(Exception exception) + { + var payload = new TestRunRequestPayload() + { + Sources = new List() { "a", "b" }, + RunSettings = DefaultRunsettings + }; + + var createRunRequestCalled = 0; + TestRunCriteria observedCriteria = null; + var mockRunRequest = new Mock(); + this.mockTestPlatform.Setup(mt => mt.CreateTestRunRequest(It.IsAny(), It.IsAny())).Callback( + (IRequestData requestData, TestRunCriteria runCriteria) => + { + createRunRequestCalled++; + observedCriteria = runCriteria; + }).Returns(mockRunRequest.Object); + + mockRunRequest.Setup(mr => mr.ExecuteAsync()).Throws(exception); + + var mockRunEventsRegistrar = new Mock(); + var mockCustomlauncher = new Mock(); + + this.testRequestManager.RunTests(payload, mockCustomlauncher.Object, mockRunEventsRegistrar.Object, this.protocolConfig); + } + + private void DiscoverTestsIfThrowsExceptionShouldThrowOut(Exception exception) + { + var payload = new DiscoveryRequestPayload() + { + Sources = new List() { "a.dll", "b.dll" }, + RunSettings = DefaultRunsettings + }; + + DiscoveryCriteria observedCriteria = null; + var mockDiscoveryRequest = new Mock(); + this.mockTestPlatform.Setup(mt => mt.CreateDiscoveryRequest(It.IsAny(), It.IsAny())).Callback( + (IRequestData requestData, DiscoveryCriteria discoveryCriteria) => + { + observedCriteria = discoveryCriteria; + }).Returns(mockDiscoveryRequest.Object); + + mockDiscoveryRequest.Setup(mr => mr.DiscoverAsync()).Throws(exception); + + var mockDiscoveryEventsRegistrar = new Mock(); + var mockCustomlauncher = new Mock(); + + this.testRequestManager.DiscoverTests(payload, mockDiscoveryEventsRegistrar.Object, this.protocolConfig); + } } } \ No newline at end of file