Before we having look at how to integrate these three test frameworks, let’s have a look at their roles/responsibilities in the process.
NUnit: Executes unit tests. It’ll provide success or failure of the unit tests execution.
PartCover: Read the execution result of unit tests and produce code coverage information.
ReportGenerator: Render code coverage report from .xml file generated by PartCover.
Here’s the script (.bat) file to integrate these three apps together as one stop shop.
"[YourPath]\PartCover.exe" --target=[YourPath]\nunit.exe --output=mytestresult.xml --include=[YourAssemblyName*]*
ECHO PartCover executed!
"[YourPath]\bin\ReportGenerator.exe" C:\mytestresult.xml C:\TestCodeCoverageResult
ECHO Report Generator executed!
- When the first command is executed, a GUI from NUnit will display and you need to manually trigger the execution of all unit tests.
- Then close NUnit GUI.
- Then report generator will generate the code coverage as html page.
Here’s how the code coverage report looks like:
You can have a overview of the code coverage on different level, e.g. Assembly, class etc.
If you want more comprehensive information, click the class then you’ll be able to drill into the actual implementation code:
The lines of code indicated with green means it’s been covered in unit test.
The lines of code indicated with red means it’s not been covered in unit test.