Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ body{margin:0;padding:0;padding-bottom:40px;max-width:100%;background-color:#fff
<li class='step Failed Assertion canToggle' data-toggle-target='step-3-3' >
<span>Then no money is dispensed [Exception Message: 'Boom']</span>
<div class='step FailedException' id='step-3-3'>
<code> at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs:line 65</code>
<code> at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs:line 90</code>
</div>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ body{margin:0;padding:0;padding-bottom:40px;max-width:100%;background-color:#fff
<td>
<span class='canToggle' data-toggle-target='step-1-19'>Boom</span>
<div class='step' id='step-1-19'>
<code> at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs:line 88</code>
<code> at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs:line 113</code>
</div>
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abb
<td>
<span class='canToggle' data-toggle-target='step-1-19'>Boom</span>
<div class='step FailedException' id='step-1-19'>
<code> at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs:line 88</code>
<code> at TestStack.BDDfy.Tests.Reporters.ReportTestData.GetScenarios(Boolean includeFailingScenario, Boolean includeExamples) in ...\ReportTestData.cs:line 113</code>
</div>
</td>
</tr>
Expand Down
51 changes: 51 additions & 0 deletions TestStack.BDDfy.Tests/Reporters/ReportTestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,31 @@ public IEnumerable<Story> CreateMixContainingEachTypeOfOutcome()
return stories;
}

public IEnumerable<Story> 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<Story>()
{
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<Story> CreateTwoStoriesEachWithOneFailingScenarioAndOnePassingScenarioWithThreeStepsOfFiveMillisecondsAndEachHasTwoExamples()
{
var storyMetadata1 = new StoryMetadata(typeof(RegularAccountHolderStory), "As a person", "I want ice cream", "So that I can be happy", "Happiness");
Expand Down Expand Up @@ -159,6 +184,31 @@ private List<Step> GetSadExecutionSteps()
return steps;
}

private List<Step> GetFailingExecutionSteps()
{
var steps = new List<Step>
{
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<Step> GetInconclusiveExecutionSteps()
{
var steps = new List<Step>
Expand Down Expand Up @@ -202,6 +252,7 @@ private void SetAllStepResults(IEnumerable<Step> steps, Result result)

public class RegularAccountHolderStory { }
public class GoldAccountHolderStory { }
public class PlatinumAccountHolderStory { }
public class ExampleScenario
{
public void GivenA__sign__AccountBalance() { }
Expand Down
Original file line number Diff line number Diff line change
@@ -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]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make the boom the second step so the last step is not executed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just to test the TextReporter. That is (or should be) thoroughly tested elsewhere. Is it not working?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we have removed ordering constraints, the existing tests do not cover when you mix order

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the mixed order is not tested. We have to add some for for the mixed order to the existing tests.


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 <sign> account balance
When the account holder requests money
Then money <action> dispensed

Examples:
| sign | action | Result | Errors |
| positive | is | Passed | |
| negative | is not | Failed | Step: Then money <action> 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 <sign> account balance
When the account holder requests money
Then money <action> dispensed

Examples:
| sign | action |
| positive | is |
| negative | is not |


29 changes: 29 additions & 0 deletions TestStack.BDDfy.Tests/Reporters/TextReporter/TextReporterTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
4 changes: 4 additions & 0 deletions TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<Compile Include="Arguments\MultipleArgumentsProvidedForTheSameStep.cs" />
<Compile Include="Configuration\SequentialKeyGeneratorTests.cs" />
<Compile Include="Configuration\TestRunnerTests.cs" />
<Compile Include="Reporters\TextReporter\TextReporterTests.cs" />
<Compile Include="Reporters\Html\MetroReportBuilderTests.cs" />
<Compile Include="Processors\TestRunnerTests.cs" />
<Compile Include="Reporters\Html\ClassicReportBuilderTests.cs" />
Expand Down Expand Up @@ -171,6 +172,9 @@
</ItemGroup>
<ItemGroup>
<Content Include="Reporters\Html\ClassicReportBuilderTests.ShouldProduceExpectedHtmlWithExamples.approved.txt" />
<Content Include="Reporters\Html\MetroReportBuilderTests.ShouldProduceExpectedHtmlWithExamples.approved.txt" />
<Content Include="Reporters\MarkDown\MarkDownReportBuilderTests.ShouldProduceExpectedMarkdown.approved.txt" />
<Content Include="Reporters\TextReporter\TextReporterTests.ShouldProduceExpectedReport.approved.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
Expand Down
5 changes: 1 addition & 4 deletions TestStack.BDDfy/Reporters/TextReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down