public async Task RunTestsAsyncWithSelectedTestsAndOptionsShouldSucceedOnOptions() { var options = new TestPlatformOptions(); await this.consoleWrapper.RunTestsAsync(this.testCases, "RunSettings", options, new Mock <ITestRunEventsHandler>().Object); this.mockRequestSender.Verify(rs => rs.StartTestRunAsync(this.testCases, "RunSettings", options, It.IsAny <ITestRunEventsHandler>()), Times.Once); }
public async Task DiscoverTestsAndOptionsAsyncShouldSucceedOnOptions() { var options = new TestPlatformOptions(); await this.consoleWrapper.DiscoverTestsAsync(this.testSources, null, options, new Mock <ITestDiscoveryEventsHandler2>().Object); this.mockRequestSender.Verify(rs => rs.DiscoverTestsAsync(this.testSources, null, options, It.IsAny <ITestDiscoveryEventsHandler2>()), Times.Once); }
public void CreateTestRunRequestShouldInitializeManagersWithFalseFlagWhenSkipDefaultAdaptersIsFalse() { var options = new TestPlatformOptions() { SkipDefaultAdapters = false }; InvokeCreateTestRunRequest(options); this.executionManager.Verify(dm => dm.Initialize(false), Times.Once); }
public void RunTestsWithSelectedTestsAndOptionsShouldPassOnOptions() { var options = new TestPlatformOptions() { TestCaseFilter = "PacMan" }; this.consoleWrapper.RunTests(this.testCases, "RunSettings", options, new Mock <ITestRunEventsHandler>().Object); this.mockRequestSender.Verify(rs => rs.StartTestRun(this.testCases, "RunSettings", options, It.IsAny <ITestRunEventsHandler>()), Times.Once); }
public void DiscoverTestsShouldSucceed() { var options = new TestPlatformOptions() { TestCaseFilter = "PacMan" }; this.consoleWrapper.DiscoverTests(this.testSources, null, options, new Mock <ITestDiscoveryEventsHandler2>().Object); this.mockRequestSender.Verify(rs => rs.DiscoverTests(this.testSources, null, options, It.IsAny <ITestDiscoveryEventsHandler2>()), Times.Once); }
public void CreateDiscoveryRequestShouldInitializeManagersWithTrueFlagWhenSkipDefaultAdaptersIsTrue() { var options = new TestPlatformOptions() { SkipDefaultAdapters = true }; InvokeCreateDiscoveryRequest(options); this.discoveryManager.Verify(dm => dm.Initialize(true), Times.Once); }
public async Task RunTestsAsyncWithSourcesOnOptionsUsingCustomHostShouldSucceedOnOptions() { var options = new TestPlatformOptions(); await this.consoleWrapper.RunTestsWithCustomTestHostAsync( this.testSources, "RunSettings", options, new Mock <ITestRunEventsHandler>().Object, new Mock <ITestHostLauncher>().Object); this.mockRequestSender.Verify(rs => rs.StartTestRunWithCustomHostAsync(this.testSources, "RunSettings", options, It.IsAny <ITestRunEventsHandler>(), It.IsAny <ITestHostLauncher>()), Times.Once); }
private void RunTests( IRequestData requestData, TestRunCriteria testRunCriteria, ITestRunEventsRegistrar testRunEventsRegistrar, TestPlatformOptions options) { // 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 un-serialized messages // whereas below logic needs to deserialize and do some cleanup. // While this section is cleaning up, TranslationLayer can trigger run causing multiple // threads to run the below section at the same time. lock (this.syncObject) { try { this.currentTestRunRequest = this.testPlatform.CreateTestRunRequest( requestData, testRunCriteria, options); this.testRunResultAggregator.RegisterTestRunEvents(this.currentTestRunRequest); testRunEventsRegistrar?.RegisterTestRunEvents(this.currentTestRunRequest); ((Microsoft.VisualStudio.TestPlatform.Client.TestPlatform) this.testPlatform).VStestLoggerManager = this.VSTestLoggerManager; this.TestPlatformEventSourceInstance.ExecutionRequestStart(); this.currentTestRunRequest.ExecuteAsync(); // Wait for the run completion event this.currentTestRunRequest.WaitForCompletion(); } catch (Exception ex) { EqtTrace.Error("TestRequestManager.RunTests: failed to run tests: {0}", ex); testRunResultAggregator.MarkTestRunFailed(); throw; } finally { if (this.currentTestRunRequest != null) { this.testRunResultAggregator.UnregisterTestRunEvents(this.currentTestRunRequest); testRunEventsRegistrar?.UnregisterTestRunEvents(this.currentTestRunRequest); this.currentTestRunRequest.Dispose(); this.currentTestRunRequest = null; } } } }
private IRunResults RunTestSession(Dictionary <int, ITestGuids> mutantTestsMap, bool runAllTests, string runSettings, Action <RunEventHandler> updateHandler = null, int retries = 0) { using var eventHandler = new RunEventHandler(_vsTests, _logger, RunnerId); void HandlerVsTestFailed(object sender, EventArgs e) => _vsTestFailed = true; void HandlerUpdate(object sender, EventArgs e) => updateHandler?.Invoke(eventHandler); var strykerVsTestHostLauncher = _hostBuilder(_id); eventHandler.VsTestFailed += HandlerVsTestFailed; eventHandler.ResultsUpdated += HandlerUpdate; _aborted = false; var options = new TestPlatformOptions { TestCaseFilter = _options.TestCaseFilter }; if (runAllTests) { _vsTestConsole.RunTestsWithCustomTestHost(_sources, runSettings, options, eventHandler, strykerVsTestHostLauncher); } else { _vsTestConsole.RunTestsWithCustomTestHost(mutantTestsMap.SelectMany(m => m.Value.GetGuids()).Select(t => _vsTests[t].Case), runSettings, options, eventHandler, strykerVsTestHostLauncher); } // Test host exited signal comes after the run completed strykerVsTestHostLauncher.WaitProcessExit(); // At this point, run must have complete. Check signal for true eventHandler.WaitEnd(); eventHandler.ResultsUpdated -= HandlerUpdate; eventHandler.VsTestFailed -= HandlerVsTestFailed; if (!_vsTestFailed || retries > 10) { return(eventHandler); } _vsTestConsole = PrepareVsTestConsole(); _vsTestFailed = false; return(RunTestSession(mutantTestsMap, true, runSettings, updateHandler, ++retries)); }
private void InvokeCreateTestRunRequest(TestPlatformOptions options = null) { this.executionManager.Setup(dm => dm.Initialize(false)).Verifiable(); this.testEngine.Setup(te => te.GetExecutionManager(this.mockRequestData.Object, this.hostManager.Object, It.IsAny <TestRunCriteria>())).Returns(this.executionManager.Object); this.testEngine.Setup(te => te.GetExtensionManager()).Returns(this.extensionManager.Object); this.testEngine.Setup(te => te.GetLoggerManager(this.mockRequestData.Object)).Returns(this.loggerManager.Object); var tp = new TestableTestPlatform(this.testEngine.Object, this.hostManager.Object); var testRunCriteria = new TestRunCriteria(new List <string> { "foo" }, 10); this.hostManager.Setup(hm => hm.GetTestSources(testRunCriteria.Sources)) .Returns(testRunCriteria.Sources); tp.CreateTestRunRequest(this.mockRequestData.Object, testRunCriteria, options); }
/// <inheritdoc/> public ITestRunRequest CreateTestRunRequest( IRequestData requestData, TestRunCriteria testRunCriteria, TestPlatformOptions options) { if (testRunCriteria == null) { throw new ArgumentNullException(nameof(testRunCriteria)); } this.AddExtensionAssemblies(testRunCriteria.TestRunSettings); var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(testRunCriteria.TestRunSettings); // Update extension assemblies from source when design mode is false. if (!runConfiguration.DesignMode) { this.AddExtensionAssembliesFromSource(testRunCriteria); } // Initialize loggers. var loggerManager = this.TestEngine.GetLoggerManager(requestData); loggerManager.Initialize(testRunCriteria.TestRunSettings); SubscribeLogger(loggerManager, this.VStestLoggerManager); var testHostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(testRunCriteria.TestRunSettings); ThrowExceptionIfTestHostManagerIsNull(testHostManager, testRunCriteria.TestRunSettings); testHostManager.Initialize(TestSessionMessageLogger.Instance, testRunCriteria.TestRunSettings); // NOTE: The custom launcher should not be set when we have test session info available. if (testRunCriteria.TestHostLauncher != null) { testHostManager.SetCustomLauncher(testRunCriteria.TestHostLauncher); } var executionManager = this.TestEngine.GetExecutionManager(requestData, testHostManager, testRunCriteria); executionManager.Initialize(options?.SkipDefaultAdapters ?? false); return(new TestRunRequest(requestData, testRunCriteria, executionManager, loggerManager)); }
/// <inheritdoc/> public IDiscoveryRequest CreateDiscoveryRequest( IRequestData requestData, DiscoveryCriteria discoveryCriteria, TestPlatformOptions options) { if (discoveryCriteria == null) { throw new ArgumentNullException(nameof(discoveryCriteria)); } // Update cache with Extension folder's files. this.AddExtensionAssemblies(discoveryCriteria.RunSettings); // Update extension assemblies from source when design mode is false. var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(discoveryCriteria.RunSettings); if (!runConfiguration.DesignMode) { this.AddExtensionAssembliesFromSource(discoveryCriteria.Sources); } // Initialize loggers. var loggerManager = this.TestEngine.GetLoggerManager(requestData); loggerManager.Initialize(discoveryCriteria.RunSettings); SubscribeLogger(loggerManager, this.VStestLoggerManager); var testHostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(discoveryCriteria.RunSettings); ThrowExceptionIfTestHostManagerIsNull(testHostManager, discoveryCriteria.RunSettings); testHostManager.Initialize(TestSessionMessageLogger.Instance, discoveryCriteria.RunSettings); var discoveryManager = this.TestEngine.GetDiscoveryManager(requestData, testHostManager, discoveryCriteria); discoveryManager.Initialize(options?.SkipDefaultAdapters ?? false); return(new DiscoveryRequest(requestData, discoveryCriteria, discoveryManager, loggerManager)); }
public void RunTestsWithSourcesAndOptionsUsingACustomHostShouldPassOnOptions() { var options = new TestPlatformOptions() { TestCaseFilter = "PacMan" }; this.consoleWrapper.RunTestsWithCustomTestHost( this.testSources, "RunSettings", options, new Mock <ITestRunEventsHandler>().Object, new Mock <ITestHostLauncher>().Object); this.mockRequestSender.Verify( rs => rs.StartTestRunWithCustomHost( this.testSources, "RunSettings", options, It.IsAny <ITestRunEventsHandler>(), It.IsAny <ITestHostLauncher>()), Times.Once); }
public void RunTestsWithCustomTestHost(IEnumerable <TestCase> testCases, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler, ITestHostLauncher customTestHostLauncher) => inner.RunTestsWithCustomTestHost(testCases, runSettings, options, testRunEventsHandler, customTestHostLauncher);
public void RunTests(IEnumerable <TestCase> testCases, string runSettings, TestPlatformOptions options, ITestRunEventsHandler testRunEventsHandler) => inner.RunTests(testCases, runSettings, options, testRunEventsHandler);
public void DiscoverTests(IEnumerable <string> sources, string discoverySettings, TestPlatformOptions options, ITestDiscoveryEventsHandler2 discoveryEventsHandler) => inner.DiscoverTests(sources, discoverySettings, options, discoveryEventsHandler);