protected async override Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator) { var output = string.Empty; TestOutputHelper testOutputHelper = null; foreach (object obj in this.ConstructorArguments) { testOutputHelper = obj as TestOutputHelper; if (testOutputHelper != null) { break; } } if (testOutputHelper != null) { testOutputHelper.Initialize(this.MessageBus, this.Test); } var tuple = await new StepInvoker(this.step, this.body, aggregator, this.CancellationTokenSource).RunAsync(); this.disposables.AddRange(tuple.Item2); if (testOutputHelper != null) { output = testOutputHelper.Output; testOutputHelper.Uninitialize(); } return(Tuple.Create(tuple.Item1, output)); }
/// <inheritdoc /> protected override async Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator) { var output = string.Empty; TestOutputHelper testOutputHelper = null; foreach (var obj in ConstructorArguments) { testOutputHelper = obj as TestOutputHelper; if (testOutputHelper != null) { break; } } testOutputHelper?.Initialize(MessageBus, Test); //TODO: Add execution time, if strictly necessary - the NBench values are certainly more accurate. var executionTime = await InvokeTestMethodAsync(aggregator); if (testOutputHelper != null) { output = testOutputHelper.Output; testOutputHelper.Uninitialize(); } return(Tuple.Create(executionTime, output)); }
/// <inheritdoc/> protected override async Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator) { var output = string.Empty; TestOutputHelper testOutputHelper = null; foreach (object obj in ConstructorArguments) { testOutputHelper = obj as TestOutputHelper; if (testOutputHelper != null) { break; } } if (testOutputHelper != null) { testOutputHelper.Initialize(MessageBus, Test); } var executionTime = await InvokeTestMethodAsync(aggregator).ConfigureAwait(false); if (testOutputHelper != null) { output = testOutputHelper.Output; testOutputHelper.Uninitialize(); } return(Tuple.Create(executionTime, output)); }
protected override async Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator) { // copy from XunitTestRunner var output = string.Empty; TestOutputHelper testOutputHelper = null; foreach (object obj in ConstructorArguments) { testOutputHelper = obj as TestOutputHelper; if (testOutputHelper != null) { break; } } if (testOutputHelper != null) { testOutputHelper.Initialize(MessageBus, Test); } var executionTime = await InvokeTestMethodAsync(aggregator); if (testOutputHelper != null) { output = testOutputHelper.Output; testOutputHelper.Uninitialize(); } // save the exceptions that were thrown during the test, in case this is needed ExceptionAggregator?.Aggregate(aggregator); return(Tuple.Create(executionTime, output)); }
protected override async Task AfterTestMethodInvokedAsync() { await base.AfterTestMethodInvokedAsync(); if (_output != null) { _output.Uninitialize(); } }
protected override async Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator) { using (var testLifetimeScope = _testClassLifetimeScope.BeginLifetimeScope(AutofacTestScopes.Test, builder => builder.RegisterModules(TestClass))) { TestOutputHelper testOutputHelper = testLifetimeScope.Resolve <TestOutputHelper>(); testOutputHelper.Initialize(MessageBus, Test); decimal seconds = await new AutofacTestInvoker(testLifetimeScope, Test, MessageBus, TestClass, ConstructorArguments, TestMethod, TestMethodArguments, BeforeAfterAttributes, aggregator, CancellationTokenSource).RunAsync(); string output = testOutputHelper.Output; testOutputHelper.Uninitialize(); return(Tuple.Create(seconds, output)); } }
protected override async Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator) { if (_ownsTestOutputHelper) { _testOutputHelper.Initialize(MessageBus, Test); } var result = await base.InvokeTestAsync(aggregator); if (_ownsTestOutputHelper) { // Update result with output if we created our own ITestOutputHelper. // The string returned from this method is what VS displays as the test output. result = new Tuple <decimal, string>(result.Item1, _testOutputHelper.Output); _testOutputHelper.Uninitialize(); } return(result); }
protected override async Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator) { _testOutputHelper = FindOutputHelperInArguments(ConstructorArguments); var shouldOwnTestOutputHelper = _testOutputHelper == null; if (shouldOwnTestOutputHelper) { _testOutputHelper = new TestOutputHelper(); _testOutputHelper.Initialize(MessageBus, Test); } var executionResult = await base.InvokeTestAsync(aggregator); if (shouldOwnTestOutputHelper) { executionResult = new Tuple <decimal, string>(executionResult.Item1, _testOutputHelper.Output); _testOutputHelper.Uninitialize(); } return(executionResult); }
protected override async Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator) { if (_ownsTestOutputHelper) { _testOutputHelper.Initialize(MessageBus, Test); } var retryAttribute = GetRetryAttribute(TestMethod); var result = retryAttribute is null ? await base.InvokeTestAsync(aggregator).ConfigureAwait(false) : await RunTestCaseWithRetryAsync(retryAttribute, aggregator).ConfigureAwait(false); if (_ownsTestOutputHelper) { // Update result with output if we created our own ITestOutputHelper. // The string returned from this method is what VS displays as the test output. result = new Tuple <decimal, string>(result.Item1, _testOutputHelper.Output); _testOutputHelper.Uninitialize(); } return(result); }
/// <summary> /// Invoke the test method. /// </summary> /// <param name="aggregator"> The exception aggregator used to run code and collect exceptions. </param> /// <returns> A tuple that conains the ellapsed time and the test output. </returns> protected async override Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator) { TestContext.EnableOutput = EnableOutput; if (EnableOutput) { TestOutputHelper output = null; decimal item = default; string message = default; try { output = new TestOutputHelper(); output.Initialize(base.MessageBus, base.Test); TestContext.TestOutput = output; item = await InvokeTestMethodAsync(aggregator); } finally { if (output != null) { message = output.Output; output.Uninitialize(); TestContext.TestOutput = null; } } return(Tuple.Create(item, message)); } else { decimal item = await InvokeTestMethodAsync(aggregator); return(Tuple.Create(item, string.Empty)); } }
protected override async Task <RunSummary> RunTestAsync() { var test = new XunitTest(TestCase, TestCase.DisplayName); //TODO: this is a pickle, we could use the Compiler/Pickle interfaces from the Gherkin parser var summary = new RunSummary() { Total = 1 }; string output = ""; var gherkinDocument = await this.TestCase.FeatureTypeInfo.GetDocumentAsync(); Scenario scenario = null; if (gherkinDocument.SpecFlowFeature != null) { if (TestCase.IsScenarioOutline) { var scenarioOutline = gherkinDocument.SpecFlowFeature.ScenarioDefinitions.OfType <ScenarioOutline>().FirstOrDefault(s => s.Name == TestCase.Name); if (scenarioOutline != null && SpecFlowParserHelper.GetExampleRowById(scenarioOutline, TestCase.ExampleId, out var example, out var exampleRow)) { scenario = SpecFlowParserHelper.CreateScenario(scenarioOutline, example, exampleRow); } } else { scenario = gherkinDocument.SpecFlowFeature.ScenarioDefinitions.OfType <Scenario>().FirstOrDefault(s => s.Name == TestCase.Name); } } string skipReason = null; if (scenario == null) { skipReason = $"Unable to find Scenario: {TestCase.DisplayName}"; } else if (gherkinDocument.SpecFlowFeature.Tags.GetTags().Concat(scenario.Tags.GetTags()).Contains("ignore")) { skipReason = "Ignored"; } if (skipReason != null) { summary.Skipped++; if (!MessageBus.QueueMessage(new TestSkipped(test, skipReason))) { CancellationTokenSource.Cancel(); } } else { var aggregator = new ExceptionAggregator(Aggregator); if (!aggregator.HasExceptions) { aggregator.Run(() => { var stopwatch = Stopwatch.StartNew(); testOutputHelper.Initialize(MessageBus, test); try { RunScenario(gherkinDocument, scenario); } finally { stopwatch.Stop(); summary.Time = (decimal)stopwatch.Elapsed.TotalSeconds; output = testOutputHelper.Output; testOutputHelper.Uninitialize(); } } ); } var exception = aggregator.ToException(); TestResultMessage testResult; if (exception == null) { testResult = new TestPassed(test, summary.Time, output); } else { testResult = new TestFailed(test, summary.Time, output, exception); summary.Failed++; } if (!CancellationTokenSource.IsCancellationRequested) { if (!MessageBus.QueueMessage(testResult)) { CancellationTokenSource.Cancel(); } } } if (!MessageBus.QueueMessage(new TestFinished(test, summary.Time, output))) { CancellationTokenSource.Cancel(); } return(summary); }