public void ManyTeardownsInASingleStep(Type feature, ITestResultMessage[] results) { "Given a step with many teardowns" .f(() => feature = typeof(StepWithManyTeardowns)); "When running the scenario" .f(() => results = this.Run<ITestResultMessage>(feature)); #if !V2 "Then there should be two results" .f(() => results.Length.Should().Be(2)); #else "Then there should be one resilt" .f(() => results.Length.Should().Be(1)); #endif "And there should be no failures" .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>()); #if !V2 "And the first result should be generated by the step" .f(() => results[0].Test.DisplayName.Should().NotContainEquivalentOf("(Teardown)")); "And the second result should be generated by the teardown" .f(() => results[1].Test.DisplayName.Should().Contain("(Teardown)")); #endif "Ann the teardowns should be executed in reverse order after the step" .f(() => typeof(TeardownFeature).GetTestEvents() .Should().Equal("step1", "teardown3", "teardown2", "teardown1")); }
public void FailureBeforeForcedStep(Type feature, ITestResultMessage[] results) { ("Given a scenario with two empty steps, " + "a failing step with continuation, " + "two more empty steps, " + "a failing step and " + "another empty step") .f(() => feature = typeof(Steps)); "When I run the scenarios" .f(() => results = this.Run<ITestResultMessage>(feature)); "Then there should be 7 results" .f(() => results.Length.Should().Be(7)); "Then the first and second results are passes" .f(() => results.Take(2).Should().ContainItemsAssignableTo<ITestPassed>()); "And the third result is a failure" .f(() => results.Skip(2).Take(1).Should().ContainItemsAssignableTo<ITestFailed>()); "And the fourth and fifth results are passes" .f(() => results.Skip(3).Take(2).Should().ContainItemsAssignableTo<ITestPassed>()); "And the sixth result is a failure" .f(() => results.Skip(5).Take(1).Should().ContainItemsAssignableTo<ITestFailed>()); "And the seventh result is a skip" .f(() => results.Skip(6).Take(1).Should().ContainItemsAssignableTo<ITestSkipped>()); }
void LogFinish(ITestResultMessage testResult) { Log.LogMessage(MessageImportance.High, "##teamcity[testFinished name='{0}' duration='{1}' flowId='{2}']", TeamCityEscape(testResult.Test.DisplayName), (int)(testResult.ExecutionTime * 1000M), ToFlowId(testResult.TestCollection.DisplayName)); }
void LogFinish(ITestResultMessage testResult) { Console.WriteLine("##teamcity[testFinished name='{0}' duration='{1}' flowId='{2}']", TeamCityEscape(testResult.Test.DisplayName), (int)(testResult.ExecutionTime * 1000M), ToFlowId(testResult.TestCollection.DisplayName)); }
private static string Format(ITestResultMessage result, int index) { return string.Format( CultureInfo.InvariantCulture, "Result {0}: {1}", (++index).ToString(CultureInfo.InvariantCulture), result); }
/// <summary> /// /// </summary> /// <param name="testCase"></param> /// <param name="testResult"></param> public TestResultViewModel(TestCaseViewModel testCase, ITestResultMessage testResult) { if (testCase == null) throw new ArgumentNullException(nameof(testCase)); TestCase = testCase; TestResultMessage = testResult; if (testResult != null) testCase.UpdateTestState(this); }
void LogFinish(ITestResultMessage testResult) { var formattedName = Escape(displayNameFormatter.DisplayName(testResult.Test)); if (!string.IsNullOrWhiteSpace(testResult.Output)) { logger.LogImportantMessage($"##teamcity[testStdOut name='{formattedName}' out='{Escape(testResult.Output)}']"); } logger.LogImportantMessage($"##teamcity[testFinished name='{formattedName}' duration='{(int)(testResult.ExecutionTime * 1000M)}' flowId='{ToFlowId(testResult.TestCollection.DisplayName)}']"); }
public void AsyncScenario(Type feature, ITestResultMessage[] results) { "Given an async scenario" .f(() => feature = typeof(FeatureWithAsyncScenario)); "When I run the scenarios" .f(() => results = this.Run<ITestResultMessage>(feature)); "Then the result should be a pass" .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>()); }
public void ScenariosWithTraits( string traitValue, int expectedResultCount, Type feature, ITestResultMessage[] results) { "Given two single step scenarios, 'foo' traits of 'bar' and 'baz' respectively" .x(() => feature = typeof(TwoSingleStepScenariosWithFooTraitsOfBarAndBazRespectively)); "When I run the feature specifying the 'foo' trait of '{0}'" .x(() => results = this.Run<ITestResultMessage>(feature, "foo", traitValue)); "Then there is only {1} result" .x(() => results.Count().Should().Be(expectedResultCount)); }
public static TestResult ToTdNetTestResult(this ITestResultMessage testResult, TestState testState, int totalTests) { return(new TestResult { FixtureType = testResult.TestCase.GetClass(), Method = testResult.TestCase.GetMethod(), Name = testResult.Test.DisplayName, State = testState, TimeSpan = new TimeSpan((long)(10000.0M * testResult.ExecutionTime)), TotalTests = totalTests, }); }
void LogFinish(ITestResultMessage testResult) { var formattedName = TeamCityEscape(displayNameFormatter.DisplayName(testResult.Test)); if (!string.IsNullOrWhiteSpace(testResult.Output)) console.WriteLine("##teamcity[testStdOut name='{0}' out='{1}']", formattedName, TeamCityEscape(testResult.Output)); console.WriteLine("##teamcity[testFinished name='{0}' duration='{1}' flowId='{2}']", formattedName, (int)(testResult.ExecutionTime * 1000M), ToFlowId(testResult.TestCollection.DisplayName)); }
XElement CreateTestResultElement(ITestResultMessage testResult, string resultText) { var collectionElement = GetTestCollectionElement(testResult.TestCase.TestMethod.TestClass.TestCollection); var testResultElement = new XElement("test", new XAttribute("name", XmlEscape(testResult.Test.DisplayName)), new XAttribute("type", testResult.TestCase.TestMethod.TestClass.Class.Name), new XAttribute("method", testResult.TestCase.TestMethod.Method.Name), new XAttribute("time", testResult.ExecutionTime.ToString(CultureInfo.InvariantCulture)), new XAttribute("result", resultText) ); if (!string.IsNullOrWhiteSpace(testResult.Output)) { testResultElement.Add(new XElement("output", new XCData(testResult.Output))); } if (testResult.TestCase.SourceInformation != null) { if (testResult.TestCase.SourceInformation.FileName != null) { testResultElement.Add(new XAttribute("source-file", testResult.TestCase.SourceInformation.FileName)); } if (testResult.TestCase.SourceInformation.LineNumber != null) { testResultElement.Add(new XAttribute("source-line", testResult.TestCase.SourceInformation.LineNumber.GetValueOrDefault())); } } if (testResult.TestCase.Traits != null && testResult.TestCase.Traits.Count > 0) { var traitsElement = new XElement("traits"); foreach (var key in testResult.TestCase.Traits.Keys) { foreach (var value in testResult.TestCase.Traits[key]) { traitsElement.Add( new XElement("trait", new XAttribute("name", XmlEscape(key)), new XAttribute("value", XmlEscape(value)) ) ); } } testResultElement.Add(traitsElement); } collectionElement.Add(testResultElement); return(testResultElement); }
private void RaiseTestSkippedCase(ITestResultMessage message, IEnumerable <ITestCase> testCases, ITestCase testCase) { SkippedTests++; OnInfo($"\t[IGNORED] {testCase.DisplayName}"); LogTestDetails(message.Test, log: OnDebug); LogTestOutput(message, log: OnDiagnostic); ReportTestCases(" Associated", testCases, log: OnDiagnostic); // notify that the test completed because it was skipped OnTestCompleted(( TestName: message.Test.DisplayName, TestResult: TestResult.Skipped )); }
public static TestResultWrapper ToTestResult(this ITestResultMessage result, TestOutcome outcome) { var tr = new TestResult(result.TestCase.ToTest().Wrapped) { Outcome = Convert(outcome), Duration = TimeSpan.FromSeconds((double)result.ExecutionTime), ErrorMessage = Conditional(result, (IFailureInformation r) => string.Join(Environment.NewLine, r.Messages)), ErrorStackTrace = Conditional(result, (IFailureInformation r) => string.Join(Environment.NewLine, r.StackTraces)) }; tr.Messages.Add(result.Output); return(tr.Wrap()); }
/// <summary> /// /// </summary> /// <param name="testCase"></param> /// <param name="testResult"></param> public TestResultViewModel(TestCaseViewModel testCase, ITestResultMessage testResult) { if (testCase == null) { throw new ArgumentNullException(nameof(testCase)); } TestCase = testCase; TestResultMessage = testResult; if (testResult != null) { testCase.UpdateTestState(this); } }
void LogFinish(ITestResultMessage testResult) { var formattedName = TeamCityEscape(displayNameFormatter.DisplayName(testResult.Test)); if (!string.IsNullOrWhiteSpace(testResult.Output)) { Log.LogMessage(MessageImportance.High, "##teamcity[testStdOut name='{0}' out='{1}']", formattedName, TeamCityEscape(testResult.Output)); } Log.LogMessage(MessageImportance.High, "##teamcity[testFinished name='{0}' duration='{1}' flowId='{2}']", formattedName, (int)(testResult.ExecutionTime * 1000M), ToFlowId(testResult.TestCollection.DisplayName)); }
public void MemberDataProperty(Type feature, ITestResultMessage[] results) { "Given {0}" .f(() => { }); "When I run the scenario" .f(() => results = this.Run<ITestResultMessage>(feature)); "Then there should be three results" .f(() => results.Length.Should().Be(3)); "Then each of the member data value sets should be passed into the scenario" .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>()); }
public void OnMessage(IMessageSinkMessage message) { switch (message) { case ITestPassed testPassed: case ITestFailed testFailed: TestResultMessage = (TestResultMessage)message; return; case ITestCaseFinished testFinished: break; default: return; } }
public void ThrowsAfter(Type feature, ITestResultMessage[] results) { "Given a scenario with a throw after attribute" .f(() => feature = typeof(ScenarioWithThrowAfterAttribute)); "When I run the scenario" .f(() => results = this.Run<ITestResultMessage>(feature)); #if V2 "Then there is a single test failure" .f(() => results.Should().ContainSingle(result => result is ITestFailed)); #else "Then there are three test failures" .f(() => results.OfType<ITestFailed>().Count().Should().Be(3)); #endif }
public void BeforeAfterAttribute(Type feature, ITestResultMessage[] results) { "Given a scenario with a before and after attribute" .f(() => feature = typeof(ScenarioWithBeforeAfterTestAttribute)); "When I run the scenario" .f(() => results = this.Run<ITestResultMessage>(feature)); #if !V2 "Then the attributes before and after methods are called before and after each step" .f(() => typeof(BeforeAfterTestFeature).GetTestEvents().Should().Equal( "before1", "step1", "after1", "before2", "step2", "after2", "before3", "step3", "after3")); #else "Then the attributes before and after methods are called before and after the scenario" .f(() => typeof(BeforeAfterTestFeature).GetTestEvents().Should().Equal( "before1", "step1", "step2", "step3", "after1")); #endif }
public void TeardownsWhichThrowExceptionsWhenExecuted(Type feature, ITestResultMessage[] results) { "Given a step with three teardowns which throw exceptions when executed" .f(() => feature = typeof(StepWithThreeBadTeardowns)); "When running the scenario" .f(() => results = this.Run<ITestResultMessage>(feature)); "Then there should be two results" .f(() => results.Length.Should().Be(2)); "And the first result should be a pass" .f(() => results[0].Should().BeAssignableTo<ITestPassed>()); "And the second result should be a failure" .f(() => results[1].Should().BeAssignableTo<ITestFailed>()); "Then the teardowns should be executed in reverse order after the step" .f(() => typeof(TeardownFeature).GetTestEvents() .Should().Equal("step1", "teardown3", "teardown2", "teardown1")); }
public void ADisposableWhichThrowExceptionsWhenDisposed(Type feature, ITestResultMessage[] results) { "Given a step with three disposables which throw exceptions when disposed" .f(() => feature = typeof(StepWithThreeBadDisposables)); "When running the scenario" .f(() => results = this.Run<ITestResultMessage>(feature)); "Then the there should be at least two results" .f(() => results.Length.Should().BeGreaterOrEqualTo(2)); "And the first n-1 results should be passes" .f(() => results.Reverse().Skip(1).Should().ContainItemsAssignableTo<ITestPassed>()); "And the last result should be a failure" .f(() => results.Reverse().First().Should().BeAssignableTo<ITestFailed>()); "And the disposables should be disposed in reverse order" .f(() => typeof(ObjectDisposalFeature).GetTestEvents() .Should().Equal("disposed3", "disposed2", "disposed1")); }
async void MakeTestResultViewModel(ITestResultMessage testResult, TestState outcome) { var tcs = new TaskCompletionSource <TestResultViewModel>(TaskCreationOptions.RunContinuationsAsynchronously); TestCaseViewModel testCase; if (!testCases.TryGetValue(testResult.TestCase, out testCase)) { // no matching reference, search by Unique ID as a fallback testCase = testCases.FirstOrDefault(kvp => kvp.Key.UniqueID?.Equals(testResult.TestCase.UniqueID) ?? false).Value; if (testCase == null) { return; } } // Create the result VM on the UI thread as it updates properties context.Post(_ => { var result = new TestResultViewModel(testCase, testResult) { Duration = TimeSpan.FromSeconds((double)testResult.ExecutionTime) }; if (outcome == TestState.Failed) { result.ErrorMessage = ExceptionUtility.CombineMessages((ITestFailed)testResult); result.ErrorStackTrace = ExceptionUtility.CombineStackTraces((ITestFailed)testResult); } tcs.TrySetResult(result); }, null); var r = await tcs.Task; listener.RecordResult(r); // bring it back to the threadpool thread }
public void ManyTeardownsInManySteps(Type feature, ITestResultMessage[] results) { "Given two steps with three teardowns each" .f(() => feature = typeof(TwoStepsWithThreeTeardownsEach)); "When running the scenario" .f(() => results = this.Run<ITestResultMessage>(feature)); #if !V2 "Then there should be three results" .f(() => results.Length.Should().Be(3)); #else "Then there should be two results" .f(() => results.Length.Should().Be(2)); #endif "And there should be no failures" .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>()); "And the teardowns should be executed in reverse order after the steps" .f(() => typeof(TeardownFeature).GetTestEvents().Should().Equal( "step1", "step2", "teardown6", "teardown5", "teardown4", "teardown3", "teardown2", "teardown1")); }
public void BackgroundSteps(Type feature, ITestResultMessage[] results) { "Given a {0}" .f(() => { }); "When I run the scenarios" .f(() => results = this.Run<ITestResultMessage>(feature)); "Then the background steps are run before each scenario" .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>()); "And there are eight results" .f(() => results.Length.Should().Be(8)); "And the background steps have '(Background)' in their names" .f(() => { foreach (var result in results.Take(2).Concat(results.Skip(4).Take(2))) { result.Test.DisplayName.Should().Contain("(Background)"); } }); }
void LogFinish(ITestResultMessage testResult) { var displayName = TeamCityEscape(GetDisplayName(testResult.Test)); if (!String.IsNullOrEmpty(testResult.Output)) { LogMessage(displayName, false, "##teamcity[testStdOut name='{0}' out='{1}' flowId='{2}']", displayName, TeamCityEscape(testResult.Output), ToFlowId(testResult.TestCollection.DisplayName)); } else if (testResult is ITestSkipped) { var skipped = (ITestSkipped)testResult; LogMessage(displayName, false, "##teamcity[testStdOut name='{0}' out='{1}' flowId='{2}']", displayName, TeamCityEscape(skipped.Reason), ToFlowId(testResult.TestCollection.DisplayName)); } LogMessage(displayName, true, "##teamcity[testFinished name='{0}' duration='{1}' flowId='{2}']", displayName, (int)(testResult.ExecutionTime * 1000M), ToFlowId(testResult.TestCollection.DisplayName)); }
public void ManyDisposablesInASingleStep(Type feature, ITestResultMessage[] results) { "Given {0}" .f(() => { }); "When running the scenario" .f(() => results = this.Run<ITestResultMessage>(feature)); "And there should be no failures" .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>()); #if !V2 "And all but the last result should not be generated by a teardown" .f(() => results.Reverse().Skip(1).Should().NotContain( result => result.Test.DisplayName.IndexOf("(Teardown)", StringComparison.OrdinalIgnoreCase) >= 0)); "And the last result should be generated by a teardown" .f(() => results.Last().Test.DisplayName.Should().Contain("(Teardown)")); #endif "And the disposables should each have been disposed in reverse order" .f(() => typeof(ObjectDisposalFeature).GetTestEvents() .Should().Equal("disposed3", "disposed2", "disposed1")); }
public void AsyncVoidStepThrowsException(Type feature, ITestResultMessage[] results) { "Given a feature with a scenario that throws an invalid operation exception"._(() => feature = typeof(AsyncVoidStepWhichThrowsException)); "When I run the scenarios"._(() => results = this.Run<ITestResultMessage>(feature)); "Then the result should be a failure"._(() => results.Should().ContainItemsAssignableTo<ITestFailed>()); "And the exception should be an invalid operation exception".f(() => results.Cast<ITestFailed>().First().ExceptionTypes.Single().Should().Be("System.InvalidOperationException")); }
public void AsyncStepExceedsTimeout(Type feature, ITestResultMessage[] results) { "Given a feature with a scenario with a single step which exceeds it's 1ms timeout"._(() => feature = typeof(AsyncStepWhichExceedsTimeout)); "When I run the scenarios"._(() => results = this.Run<ITestResultMessage>(feature)); "Then there should be one result"._(() => results.Count().Should().Be(1)); "And the result should be a failure"._(() => results.Should().ContainItemsAssignableTo<ITestFailed>()); "And the result message should be \"Test execution time exceeded: 1ms\""._(() => results.Cast<ITestFailed>().Should().OnlyContain(result => result.Messages.Single() == "Test execution time exceeded: 1ms")); }
public void DisposablesWhichCreateNewDisposablesWhenDisposed( Type feature, ITestResultMessage[] results) { ("Given a step with disposables which, when disposed," + "throw an exception and add more disposables which throw an exception when disposed") .f(() => feature = typeof(StepWithThreeRecursiveBadDisposables)); "When running the scenario" .f(() => results = this.Run<ITestResultMessage>(feature)); "Then the results should not be empty" .f(() => results.Should().NotBeEmpty()); "And the first n-2 results should not be failures" .f(() => results.Reverse().Skip(2).Should().NotContain(result => result is ITestFailed)); "And the last 2 results should be failures" .f(() => results.Reverse().Take(2).Should().ContainItemsAssignableTo<ITestFailed>()); "And the disposables should be disposed in reverse order" .f(() => typeof(ObjectDisposalFeature).GetTestEvents() .Should().Equal("disposed3", "disposed2", "disposed1")); }
XElement CreateTestResultElement(ITestResultMessage testResult, string resultText) { ITest test = testResult.Test; ITestCase testCase = testResult.TestCase; ITestMethod testMethod = testCase.TestMethod; ITestClass testClass = testMethod.TestClass; var collectionElement = GetTestCollectionElement(testClass.TestCollection); var testResultElement = new XElement("test", new XAttribute("name", XmlEscape(test.DisplayName)), new XAttribute("type", testClass.Class.Name), new XAttribute("method", testMethod.Method.Name), new XAttribute("time", testResult.ExecutionTime.ToString(CultureInfo.InvariantCulture)), new XAttribute("result", resultText) ); var testOutput = testResult.Output; if (!string.IsNullOrWhiteSpace(testOutput)) { testResultElement.Add(new XElement("output", new XCData(testOutput))); } ISourceInformation sourceInformation = testCase.SourceInformation; if (sourceInformation != null) { var fileName = sourceInformation.FileName; if (fileName != null) { testResultElement.Add(new XAttribute("source-file", fileName)); } var lineNumber = sourceInformation.LineNumber; if (lineNumber != null) { testResultElement.Add(new XAttribute("source-line", lineNumber.GetValueOrDefault())); } } var traits = testCase.Traits; if (traits != null && traits.Count > 0) { var traitsElement = new XElement("traits"); foreach (var keyValuePair in traits) { foreach (var val in keyValuePair.Value) { traitsElement.Add( new XElement("trait", new XAttribute("name", XmlEscape(keyValuePair.Key)), new XAttribute("value", XmlEscape(val)) ) ); } } testResultElement.Add(traitsElement); } collectionElement.Add(testResultElement); if (_logger != null) { _logger.LogMessage($"collectionElement: {collectionElement}"); } return(testResultElement); }
VsTestResult MakeVsTestResult(TestOutcome outcome, ITestResultMessage testResult) => MakeVsTestResult(outcome, testResult.TestCase, testResult.Test.DisplayName, (double)testResult.ExecutionTime, testResult.Output);
private VsTestResult MakeVsTestResult(TestOutcome outcome, ITestResultMessage testResult) { return(MakeVsTestResult(outcome, testResult.TestCase, testResult.TestDisplayName, (double)testResult.ExecutionTime, testResult.Output)); }
public void FailureBeforeContinuationStep(Type feature, ITestResultMessage[] results) { "Given a scenario with a failure before the continuation step" .f(() => feature = typeof(ScenarioWithFailureBeforeContinuationStep)); "When I run the scenarios" .f(() => results = this.Run<ITestResultMessage>(feature)); "Then there should be four results" .f(() => results.Length.Should().Be(4)); "Then the first result is a pass" .f(() => results.Take(1).Should().ContainItemsAssignableTo<ITestPassed>()); "And the second result is a failure" .f(() => results.Skip(1).Take(1).Should().ContainItemsAssignableTo<ITestFailed>()); "And the last two results are failures" .f(() => results.Skip(2).Should().ContainItemsAssignableTo<ITestFailed>()); }
public void MultipleContexts(Type feature, ITestResultMessage[] results) { "Given a step with a teardown and steps which generate two contexts" .f(() => feature = typeof(SingleStepTwoContexts)); "When running the scenario" .f(() => results = this.Run<ITestResultMessage>(feature)); "Then there should be no failures" .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>()); "And the teardown should be executed after each context" .f(() => typeof(TeardownFeature).GetTestEvents().Should().Equal( "step1.1", "step1.2", "step1.3", "teardown1.1", "step2.1", "step2.2", "step2.4", "teardown2.1")); }
public void MultipleContexts(Type feature, ITestResultMessage[] results) { "Given a step with a disposable and steps which generate two contexts" .f(() => feature = typeof(TwoContexts)); "When running the scenario" .f(() => results = this.Run<ITestResultMessage>(feature)); "And there should be no failures" .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>()); "And the disposable should be disposed after each context" .f(() => typeof(ObjectDisposalFeature).GetTestEvents() .Should().Equal("step1", "disposed1", "step2", "disposed2")); }
public void FailingSteps(Type feature, ITestResultMessage[] results) { "Given two steps with teardowns and a failing step" .f(() => feature = typeof(TwoStepsWithTeardownsAndAFailingStep)); "When running the scenario" .f(() => results = this.Run<ITestResultMessage>(feature)); "Then there should be one failure" .f(() => results.OfType<ITestFailed>().Count().Should().Be(1)); "And the teardowns should be executed after each step" .f(() => typeof(TeardownFeature).GetTestEvents() .Should().Equal("step1", "step2", "step3", "teardown2", "teardown1")); }
void LogTestOutput(ITestResultMessage test, Action <string> log = null, StringBuilder sb = null) { LogTestOutput(test.ExecutionTime, test.Output, log, sb); }
private static string Format(ITestResultMessage result, int index) => $"Result {(++index).ToString(CultureInfo.InvariantCulture)}: {result}";
public void DisposablesAndTeardowns(Type feature, ITestResultMessage[] results) { "Given steps with disposables and teardowns" .f(() => feature = typeof(StepsWithDisposablesAndTeardowns)); "When running the scenario" .f(() => results = this.Run<ITestResultMessage>(feature)); "And there should be no failures" .f(() => results.Should().ContainItemsAssignableTo<ITestPassed>()); "And the disposables and teardowns should be disposed/executed in reverse order" .f(() => typeof(ObjectDisposalFeature).GetTestEvents() .Should().Equal("teardown4", "disposed3", "teardown2", "disposed1")); }
XElement CreateTestResultElement(ITestResultMessage testResult, string resultText) { ITest test = testResult.Test; ITestCase testCase = testResult.TestCase; ITestMethod testMethod = testCase.TestMethod; ITestClass testClass = testMethod.TestClass; var collectionElement = GetTestCollectionElement(testClass.TestCollection); var testResultElement = new XElement("test", new XAttribute("name", XmlEscape(test.DisplayName)), new XAttribute("type", testClass.Class.Name), new XAttribute("method", testMethod.Method.Name), new XAttribute("time", testResult.ExecutionTime.ToString(CultureInfo.InvariantCulture)), new XAttribute("result", resultText) ); var testOutput = testResult.Output; if (!string.IsNullOrWhiteSpace(testOutput)) testResultElement.Add(new XElement("output", new XCData(testOutput))); ISourceInformation sourceInformation = testCase.SourceInformation; if (sourceInformation != null) { var fileName = sourceInformation.FileName; if (fileName != null) testResultElement.Add(new XAttribute("source-file", fileName)); var lineNumber = sourceInformation.LineNumber; if (lineNumber != null) testResultElement.Add(new XAttribute("source-line", lineNumber.GetValueOrDefault())); } var traits = testCase.Traits; if (traits != null && traits.Count > 0) { var traitsElement = new XElement("traits"); foreach (var keyValuePair in traits) foreach (var val in keyValuePair.Value) traitsElement.Add( new XElement("trait", new XAttribute("name", XmlEscape(keyValuePair.Key)), new XAttribute("value", XmlEscape(val)) ) ); testResultElement.Add(traitsElement); } collectionElement.Add(testResultElement); return testResultElement; }
public void FailingSteps(Type feature, ITestResultMessage[] results) { "Given {0}" .f(() => { }); "When running the scenario" .f(() => results = this.Run<ITestResultMessage>(feature)); "Then there should be one failure" .f(() => results.OfType<ITestFailed>().Count().Should().Be(1)); "And the disposables should be disposed in reverse order" .f(() => typeof(ObjectDisposalFeature).GetTestEvents() .Should().Equal("disposed3", "disposed2", "disposed1")); }
private void Register(TestOutcome outcome, ITestResultMessage result) { _sink.RecordResult(result.ToTestResult(outcome)); }
public void FailureToCompleteAStep(Type feature, ITestResultMessage[] results) { "Given a failing step with three teardowns" .f(() => feature = typeof(FailingStepWithThreeTeardowns)); "When running the scenario" .f(() => results = this.Run<ITestResultMessage>(feature)); "Then there should be one failure" .f(() => results.OfType<ITestFailed>().Count().Should().Be(1)); "And the teardowns should be executed in reverse order after the step" .f(() => typeof(TeardownFeature).GetTestEvents() .Should().Equal("step1", "teardown3", "teardown2", "teardown1")); }
void LogFinish(ITestResultMessage testResult) { var formattedName = Escape(displayNameFormatter.DisplayName(testResult.Test)); if (!string.IsNullOrWhiteSpace(testResult.Output)) logger.LogImportantMessage($"##teamcity[testStdOut name='{formattedName}' out='{Escape(testResult.Output)}']"); logger.LogImportantMessage($"##teamcity[testFinished name='{formattedName}' duration='{(int)(testResult.ExecutionTime * 1000M)}' flowId='{ToFlowId(testResult.TestCollection.DisplayName)}']"); }