Skip to content

Commit

Permalink
specflow tests for nunit execution report
Browse files Browse the repository at this point in the history
  • Loading branch information
gasparnagy committed Jun 29, 2010
1 parent c1588c6 commit 2979d9a
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 3 deletions.
79 changes: 79 additions & 0 deletions Tests/ReportingTests/NUnitExecutionReport.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Feature: Generating HTML report from NUnit execution result
In order to present the test results in a nice form
As a test manager
I want to be able to generate an HTML report from the NUnit execution result

Scenario: Summary is included in the HTML result
Given there are NUuit test execution results for the ReportingTest.SampleProject project
When I generate SpecFlow NUnit execution report
Then a report generated containing
"""
Summary
Features Success rate Scenarios Success Failed Pending Ignored
2 features 40% 5 2 1 1 1
"""


Scenario: Feature summary is included in the HTML result
Given there are NUuit test execution results for the ReportingTest.SampleProject project
When I generate SpecFlow NUnit execution report
Then a report generated containing
"""
Feature Summary
Feature Success rate Scenarios Success Failed Pending Ignored
Feature with failing scenarios 0% 3 0 1 1 1
Feature with successful scenarios 100% 2 2 0 0 0
"""


Scenario: Successful test output is included in the HTML result
Given there are NUuit test execution results for the ReportingTest.SampleProject project
When I generate SpecFlow NUnit execution report
Then a report generated containing
"""
Given I have a precondition that is successful
-> done: StepDefinitions.GivenIHaveAPreconditionThatIs("successful") (0,0s)
When I do something that works
-> done: StepDefinitions.GivenIHaveAPreconditionThatIs("works") (0,0s)
Then I have a postcondition that is successful
-> done: StepDefinitions.GivenIHaveAPreconditionThatIs("successful") (0,0s)
"""


Scenario: Pending test output is included in the HTML result
Given there are NUuit test execution results for the ReportingTest.SampleProject project
When I generate SpecFlow NUnit execution report
Then a report generated containing
"""
Given I have a pending precondition
-> No matching step definition found for the step. Use the following code to create one:
[Binding]
public class StepDefinitions
{
[Given(@"I have a pending precondition")]
public void GivenIHaveAPendingPrecondition()
{
ScenarioContext.Current.Pending();
}
}
"""


Scenario: Failing test output is included in the HTML result
Given there are NUuit test execution results for the ReportingTest.SampleProject project
When I generate SpecFlow NUnit execution report
Then a report generated containing
"""
Given I have a precondition that is failing
-> error: simulated failure
"""


Scenario: Failing test exception is included in the HTML result
Given there are NUuit test execution results for the ReportingTest.SampleProject project
When I generate SpecFlow NUnit execution report
Then a report generated containing
"""
simulated failure
at ReportingTest.SampleProject.StepDefinitions.GivenIHaveAPreconditionThatIs(String result) in
"""
190 changes: 190 additions & 0 deletions Tests/ReportingTests/NUnitExecutionReport.feature.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Tests/ReportingTests/ReportingTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
<DesignTime>True</DesignTime>
<DependentUpon>CustomXsltTemplate.feature</DependentUpon>
</Compile>
<Compile Include="NUnitExecutionReport.feature.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>NUnitExecutionReport.feature</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StepDefinitions\Setup.cs" />
<Compile Include="StepDefinitions\StepDefinitions.cs" />
Expand Down Expand Up @@ -81,6 +86,10 @@
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>CustomXsltTemplate.feature.cs</LastGenOutput>
</None>
<None Include="NUnitExecutionReport.feature">
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>NUnitExecutionReport.feature.cs</LastGenOutput>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
46 changes: 43 additions & 3 deletions Tests/ReportingTests/StepDefinitions/StepDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public void GivenThereIsAnXSLTTemplateContaining(string templateFileName, string
GenerateCustomXslt(xsltContent, templateFileName);
}

[When(@"I generate SpecFlow NUnit execution report with the custom XSLT")]
public void WhenIGenerateSpecFlowNUnitExecutionReportWithTheCustomXSLT()
[When(@"I generate SpecFlow NUnit execution report( with the custom XSLT)?")]
public void WhenIGenerateSpecFlowNUnitExecutionReportWithTheCustomXSLT(string withCustomXslt)
{
SpecFlowTool.NUnitExecutionReport(
sampleProjectInfo.ProjectFilePath,
Expand All @@ -60,9 +60,28 @@ public void ThenAReportGeneratedLike(string expectedResultContent)
AssertEqualIgnoringWhitespace(expectedResultContent, resultContent);
}

[Then(@"a report generated containing")]
public void ThenAReportGeneratedContaining(string expectedResultContent)
{
Assert.IsTrue(File.Exists(sampleProjectInfo.OutputFilePath), "no result is generated");

string resultContent = sampleProjectInfo.GetOutputFileContent();

AssertContainsIgnoringWhitespace(expectedResultContent, resultContent);
}

private void AssertEqualIgnoringWhitespace(string expectedValue, string actualValue)
{
StringAssert.AreEqualIgnoringCase(NormalizeWhitespace(expectedValue), NormalizeWhitespace(actualValue));
StringAssert.AreEqualIgnoringCase(
NormalizeWhitespace(CleanHtml(expectedValue)),
NormalizeWhitespace(CleanHtml(actualValue)));
}

private void AssertContainsIgnoringWhitespace(string expectedValue, string actualValue)
{
StringAssert.Contains(
NormalizeWhitespace(HtmlEncode(expectedValue)).ToLowerInvariant(),
NormalizeWhitespace(CleanHtml(actualValue)).ToLowerInvariant());
}

private string NormalizeWhitespace(string value)
Expand All @@ -71,6 +90,27 @@ private string NormalizeWhitespace(string value)
return whitespaceRe.Replace(value.Trim(), " ");
}

private string HtmlEncode(string value)
{
return value.Replace("<", "&lt;").Replace(">", "&gt;");
}

private string CleanHtml(string value)
{
var bodyRe = new Regex(@"\<\/?\s*body\s*\>");
var bodyMatch = bodyRe.Match(value);
if (bodyMatch.Success)
{
value = value.Substring(bodyMatch.Index + bodyMatch.Value.Length);
bodyMatch = bodyRe.Match(value);
if (bodyMatch.Success)
value = value.Substring(0, bodyMatch.Index);
}
var whitespaceRe = new Regex(@"\<.*?\>");
var result = whitespaceRe.Replace(value.Trim(), " ");
return result;
}

private string GenerateCustomXslt(string content, string templateFileName)
{
string xsltTemplate = @"<?xml version=""1.0"" encoding=""utf-8""?>
Expand Down

0 comments on commit 2979d9a

Please sign in to comment.