Test Execution Report in SpecFlow
It would be very good to generate test reports related to Acceptance tests for satisfying our requirements and providing the test statuses to Customers & Project Managers. This report provides a formatted HTML report of a test execution. The report contains a summary about the executed tests and the result and also a detailed report for the individual scenario executions.
NUnit Test Execution Report
Let me create a Test Execution Report for my previous blog on SpecFlow. In order to generate this report you have to execute the acceptance tests with the
nunit-console runner. This tool generates an XML summary about the test executions. To have the detailed scenario execution traces visible, you also need to capture the test output using the
/out and the
/labels options as it can be seen in the following example.
nunit-console.exe /labels /out=TestResult.txt /xml=TestResult.xml bin\Debug\SpecflowTest.dll
The two generated file can be used to invoke the SpecFlow report generation. If you use the output file names shown above it is enough to specify the project file path containing the feature files.
specflow.exe nunitexecutionreport SpecflowTest.csproj /out:MyResult.html
Step 1 is already executed as we are running the tests using the NUnit GUI and this automatically generates a TestResult.xml file in the bin\Debug folder as shown in the snapshot below:
Now, let me jump to the Step 2. Step 2 can be executed by using the External tools in the Visual Studio.
- Go to Tools -> External Tools
- Click on the ‘Add’ button in the ‘External Tools’ window
- Input a Title (say in my case ‘SpecFlow Test Result’)
- Input the location of SpecFlow application in the ‘Command’ field (say in my case ‘C:\Program Files (x86)\TechTalk\SpecFlow\specflow.exe’)
- Input the argument in the ‘Arguments’ field (say in my case ‘nunitexecutionreport SpecflowTest.csproj /xmlTestResult:bin\debug\TestResult.xml’)
- Input the directory info in ‘Initial directory’ field (say in my case ‘$(ProjectDir)’)
- Set the ‘Close on exit’ checkbox and hit the ‘Apply’ & ‘OK’ buttons. A new option ‘SpecFlow Test Result’ under the ‘Tools’ menu.
Generating the Test Report
- Debug the project and run the test using NUnit GUI window.
- Click on the option ‘SpecFlow Test Result’ under the ‘Tools’ menu.
- Open the ‘TestResult.html’ file present in the ‘Projects’ folder using the browser as in the snapshot below.
- Create a short-cut to the ‘TestResult.html’ file by adding the file to the Visual Studio Solution Explorer for quick viewing as in the snapshot below.