The test runner inside Visual Studio is great while developing code. In this phase I only care if tests fail and when everything works, I don’t want to be bothered. However, if I need to create a report for someone that just wants to know the high-level view, then this tool is not good enough: Too much details and no visualisation.
To create a high-level report, I need to put in effort: Copy some numbers around, create an Excel file with some graphics and then paste that back into another document. That effort needs to be redone whenever a new report is required. A better solution is needed and with Report Unit I found one that works quiet well.
Report Unit uses the output of a test runner and creates a nice HTML report. It contains a useful visualisation and allows you to drill-down from the test-project down to the single test cases:
The effort you need to create such a report is minimal. All you need is a little batch file that calls your test runner, creates a result file and then pipe it through Report Unit. I use NUnit and want to create the report in the folder HTMLReport. These commands do exactly that for all my 3 test projects:
1 2 3 4 5 6 |
del ".\HTMLReport\*.html" ".\packages\NUnit.ConsoleRunner.3.6.1\tools\nunit3-console.exe" ".\Reports.Core.Tests\bin\Debug\Reports.Core.Tests.dll" --result="Reports.Core.Tests.xml;format=nunit3" --work=".\TestResults" ".\packages\NUnit.ConsoleRunner.3.6.1\tools\nunit3-console.exe" ".\Reports.Helper.Tests\bin\Debug\Reports.Helper.Tests.dll" --result="Reports.Helper.Tests.xml;format=nunit3" --work=".\TestResults" ".\packages\NUnit.ConsoleRunner.3.6.1\tools\nunit3-console.exe" ".\Reports.Import.Tests\bin\Debug\Reports.Import.Tests.dll" --result="Reports.Import.Tests.xml;format=nunit3" --work=".\TestResults" ".\packages\ReportUnit.1.2.1\tools\ReportUnit.exe" ".\TestResults" ".\HTMLReport" |
Some remarks on this solution:
- One test project needs to add the Report Unit NuGet package (Install-Package ReportUnit) so that it is downloaded to the packages folder in your solution.
- Keep an eye on the paths you use. I always use relative paths, so that I don’t depend on a specific location in the filesystem.
- To add new projects, you simply copy one of the lines that call the test runner and modify it with the path to the new project.
- It only works when the code is pre-compiled. Should this be a problem for you, then you could trigger a compilation at the top of the script.
As soon as you have this setup working, you no longer need to copy numbers around to create a beautiful high-level report for the management.
Thank you for this info. Do you know how we can create this in visual studio itself?