diff --git a/TestStack.BDDfy.Tests/Reporters/Html/ClassicReportBuilderTests.ShouldProduceExpectedHtml.approved.txt b/TestStack.BDDfy.Tests/Reporters/Html/ClassicReportBuilderTests.ShouldProduceExpectedHtml.approved.txt index 02e7bbf5..96f73d4a 100644 --- a/TestStack.BDDfy.Tests/Reporters/Html/ClassicReportBuilderTests.ShouldProduceExpectedHtml.approved.txt +++ b/TestStack.BDDfy.Tests/Reporters/Html/ClassicReportBuilderTests.ShouldProduceExpectedHtml.approved.txt @@ -104,7 +104,7 @@ body{margin:0;padding:0;padding-bottom:40px;max-width:100%;background-color:#fff
  • Then no money is dispensed [Exception Message: 'Boom']
    - at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs:line 65 + at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs:line 90
  • diff --git a/TestStack.BDDfy.Tests/Reporters/Html/ClassicReportBuilderTests.ShouldProduceExpectedHtmlWithExamples.approved.txt b/TestStack.BDDfy.Tests/Reporters/Html/ClassicReportBuilderTests.ShouldProduceExpectedHtmlWithExamples.approved.txt index 962393f9..0d060152 100644 --- a/TestStack.BDDfy.Tests/Reporters/Html/ClassicReportBuilderTests.ShouldProduceExpectedHtmlWithExamples.approved.txt +++ b/TestStack.BDDfy.Tests/Reporters/Html/ClassicReportBuilderTests.ShouldProduceExpectedHtmlWithExamples.approved.txt @@ -113,7 +113,7 @@ body{margin:0;padding:0;padding-bottom:40px;max-width:100%;background-color:#fff Boom
    - at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs:line 88 + at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs:line 113
    diff --git a/TestStack.BDDfy.Tests/Reporters/Html/MetroReportBuilderTests.ShouldProduceExpectedHtmlWithExamples.approved.txt b/TestStack.BDDfy.Tests/Reporters/Html/MetroReportBuilderTests.ShouldProduceExpectedHtmlWithExamples.approved.txt index 4df158b4..cc441484 100644 --- a/TestStack.BDDfy.Tests/Reporters/Html/MetroReportBuilderTests.ShouldProduceExpectedHtmlWithExamples.approved.txt +++ b/TestStack.BDDfy.Tests/Reporters/Html/MetroReportBuilderTests.ShouldProduceExpectedHtmlWithExamples.approved.txt @@ -124,7 +124,7 @@ html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abb Boom
    - at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs:line 88 + at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs:line 113
    diff --git a/TestStack.BDDfy.Tests/Reporters/ReportTestData.cs b/TestStack.BDDfy.Tests/Reporters/ReportTestData.cs index a8aaa2e2..cbdf4602 100644 --- a/TestStack.BDDfy.Tests/Reporters/ReportTestData.cs +++ b/TestStack.BDDfy.Tests/Reporters/ReportTestData.cs @@ -40,6 +40,31 @@ public IEnumerable CreateMixContainingEachTypeOfOutcome() return stories; } + public IEnumerable CreateMixContainingEachTypeOfOutcomeWithOneScenarioPerStory() + { + var storyMetadata1 = new StoryMetadata(typeof(RegularAccountHolderStory), "As a person", "I want ice cream", "So that I can be happy", "Happiness"); + var storyMetadata2 = new StoryMetadata(typeof(GoldAccountHolderStory), "As an unhappy examples story", "I want to see failed steps", "So that I can diagnose what's wrong", "Unhappy examples"); + var storyMetadata3 = new StoryMetadata(typeof(PlatinumAccountHolderStory), "As a happy examples story", "I want a clean report with examples", "So that the report is clean and readable", "Happy Examples"); + + const StoryMetadata testThatReportWorksWithNoStory = null; + + var stories = new List() + { + new Story(storyMetadata1, new Scenario(typeof(HappyPathScenario), GetHappyExecutionSteps(), "Happy Path Scenario [for Happiness]")), + new Story(storyMetadata1, new Scenario(typeof(SadPathScenario), GetFailingExecutionSteps(), "Sad Path Scenario [for Happiness]")), + new Story(storyMetadata1, new Scenario(typeof(SadPathScenario), GetInconclusiveExecutionSteps(), "Inconclusive Scenario [for Happiness]")), + new Story(storyMetadata1, new Scenario(typeof(SadPathScenario), GetNotImplementedExecutionSteps(), "Not Implemented Scenario [for Happiness]")), + new Story(testThatReportWorksWithNoStory, new Scenario(typeof(HappyPathScenario), GetHappyExecutionSteps(), "Happy Path Scenario [with no story]")), + new Story(testThatReportWorksWithNoStory, new Scenario(typeof(SadPathScenario), GetFailingExecutionSteps(), "Sad Path Scenario [with no story]")), + new Story(testThatReportWorksWithNoStory, new Scenario(typeof(SadPathScenario), GetInconclusiveExecutionSteps(), "Inconclusive Scenario [with no story]")), + new Story(testThatReportWorksWithNoStory, new Scenario(typeof(SadPathScenario), GetNotImplementedExecutionSteps(), "Not Implemented Scenario [with no story]")), + new Story(storyMetadata2, GetScenarios(true, true)), + new Story(storyMetadata3, GetScenarios(false, true)), + }; + + return stories; + } + public IEnumerable CreateTwoStoriesEachWithOneFailingScenarioAndOnePassingScenarioWithThreeStepsOfFiveMillisecondsAndEachHasTwoExamples() { var storyMetadata1 = new StoryMetadata(typeof(RegularAccountHolderStory), "As a person", "I want ice cream", "So that I can be happy", "Happiness"); @@ -159,6 +184,31 @@ private List GetSadExecutionSteps() return steps; } + private List GetFailingExecutionSteps() + { + var steps = new List + { + new Step(null, new StepTitle("Given a negative account balance"), true, ExecutionOrder.Assertion, true), + new Step(null, new StepTitle("When the account holder requests money"), true, ExecutionOrder.Assertion, true), + new Step(null, new StepTitle("Then no money is dispensed"), true, ExecutionOrder.Assertion, true), + }; + + SetAllStepResults(steps, Result.Passed); + + var last = steps.Last(); + last.Result = Result.Failed; + try + { + throw new InvalidOperationException("Boom"); + } + catch (Exception ex) + { + last.Exception = ex; + } + + return steps; + } + private List GetInconclusiveExecutionSteps() { var steps = new List @@ -202,6 +252,7 @@ private void SetAllStepResults(IEnumerable steps, Result result) public class RegularAccountHolderStory { } public class GoldAccountHolderStory { } + public class PlatinumAccountHolderStory { } public class ExampleScenario { public void GivenA__sign__AccountBalance() { } diff --git a/TestStack.BDDfy.Tests/Reporters/TextReporter/TextReporterTests.ShouldProduceExpectedReport.approved.txt b/TestStack.BDDfy.Tests/Reporters/TextReporter/TextReporterTests.ShouldProduceExpectedReport.approved.txt new file mode 100644 index 00000000..56df227c --- /dev/null +++ b/TestStack.BDDfy.Tests/Reporters/TextReporter/TextReporterTests.ShouldProduceExpectedReport.approved.txt @@ -0,0 +1,116 @@ +Story: Happiness + As a person + I want ice cream + So that I can be happy + +Scenario: Happy Path Scenario [for Happiness] + Given a positive account balance + When the account holder requests money + Then money is dispensed + + +Story: Happiness + As a person + I want ice cream + So that I can be happy + +Scenario: Sad Path Scenario [for Happiness] + Given a negative account balance [Passed] + When the account holder requests money [Passed] + Then no money is dispensed [Failed] [Boom] [Details at 1 below] + +Exceptions: + 1. Boom + at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetFailingExecutionSteps() in ...\ReportTestData.cs + + +Story: Happiness + As a person + I want ice cream + So that I can be happy + +Scenario: Inconclusive Scenario [for Happiness] + Given a negative account balance [Passed] + When the account holder requests money [Passed] + Then no money is dispensed [Inconclusive] + + +Story: Happiness + As a person + I want ice cream + So that I can be happy + +Scenario: Not Implemented Scenario [for Happiness] + Given a negative account balance [Passed] + When the account holder requests money [Passed] + Then no money is dispensed [Not implemented] + + + +Scenario: Happy Path Scenario [with no story] + Given a positive account balance + When the account holder requests money + Then money is dispensed + + + +Scenario: Sad Path Scenario [with no story] + Given a negative account balance [Passed] + When the account holder requests money [Passed] + Then no money is dispensed [Failed] [Boom] [Details at 1 below] + +Exceptions: + 1. Boom + at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetFailingExecutionSteps() in ...\ReportTestData.cs + + + +Scenario: Inconclusive Scenario [with no story] + Given a negative account balance [Passed] + When the account holder requests money [Passed] + Then no money is dispensed [Inconclusive] + + + +Scenario: Not Implemented Scenario [with no story] + Given a negative account balance [Passed] + When the account holder requests money [Passed] + Then no money is dispensed [Not implemented] + + +Story: Unhappy examples + As an unhappy examples story + I want to see failed steps + So that I can diagnose what's wrong + +Scenario: Example Scenario + Given a account balance + When the account holder requests money + Then money dispensed + +Examples: +| sign | action | Result | Errors | +| positive | is | Passed | | +| negative | is not | Failed | Step: Then money dispensed failed with exception: [Boom] [Details at 1 below] | + +Exceptions: + 1. Boom + at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs + + +Story: Happy Examples + As a happy examples story + I want a clean report with examples + So that the report is clean and readable + +Scenario: Example Scenario + Given a account balance + When the account holder requests money + Then money dispensed + +Examples: +| sign | action | +| positive | is | +| negative | is not | + + diff --git a/TestStack.BDDfy.Tests/Reporters/TextReporter/TextReporterTests.cs b/TestStack.BDDfy.Tests/Reporters/TextReporter/TextReporterTests.cs new file mode 100644 index 00000000..6e083b03 --- /dev/null +++ b/TestStack.BDDfy.Tests/Reporters/TextReporter/TextReporterTests.cs @@ -0,0 +1,29 @@ +using System.Runtime.CompilerServices; +using System.Text; +using ApprovalTests; +using NUnit.Framework; +using TestStack.BDDfy.Reporters; + +namespace TestStack.BDDfy.Tests.Reporters.MarkDown +{ + [TestFixture] + public class TextReporterTests + { + [Test] + [MethodImpl(MethodImplOptions.NoInlining)] + public void ShouldProduceExpectedReport() + { + var stories = new ReportTestData().CreateMixContainingEachTypeOfOutcomeWithOneScenarioPerStory(); + var actual = new StringBuilder(); + + foreach (var story in stories) + { + var textReporter = new TextReporter(); + textReporter.Process(story); + actual.AppendLine(textReporter.ToString()); + } + + Approvals.Verify(actual.ToString(), StackTraceScrubber.Scrub); + } + } +} diff --git a/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj b/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj index 2d1ce722..3e0e7987 100644 --- a/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj +++ b/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj @@ -77,6 +77,7 @@ + @@ -171,6 +172,9 @@ + + + diff --git a/TestStack.BDDfy/Reporters/TextReporter.cs b/TestStack.BDDfy/Reporters/TextReporter.cs index 1793ce70..b3bedfc0 100644 --- a/TestStack.BDDfy/Reporters/TextReporter.cs +++ b/TestStack.BDDfy/Reporters/TextReporter.cs @@ -160,9 +160,7 @@ void ReportOnStep(Scenario scenario, Step step, bool includeResults) message = "\t" + PrefixWithSpaceIfRequired(step); if (step.Exception != null) - { - message = CreateExceptionMessage(step); - } + message += CreateExceptionMessage(step); if (step.Result == Result.Inconclusive || step.Result == Result.NotImplemented) ForegroundColor = ConsoleColor.Yellow; @@ -213,7 +211,6 @@ void ReportExceptions() static string FlattenExceptionMessage(string message) { - // ToDo: if gets complex will change it with a regex return message .Replace("\t", " ") // replace tab with one space .Replace(Environment.NewLine, ", ") // replace new line with one space