Posted by Anuraj on Sunday, November 6, 2016 Reading time :1 minute
This post is about getting code coverage of .NET Core using Opencover. This is an update post, long back I wrote a post on code coverage using ASP.NET Core in RC days. This post is using dotnet command and 1.0 version. Opencover is a code coverage tool for .NET 2 and above, support for 32 and 64 processes with both branch and sequence points; roots proudly based in PartCover - https://github.com/OpenCover/opencover/
Here is the source file, since the post is about measuring code coverage, it is a simple math libaray with Add and Divide methods.
Once library created, you can execute dotnet build command to verify everything works fine. Once it is done, you can write the unit test file. Here is the test file.
And the project.json file for unit test project.
You require global.json file in the root directory, which used to resolve the dependencies. Execute dnu restore and dnx test command to verify your unit tests. To get the code coverage, you require Open cover, which you can install via Nuget or can download and install from here https://github.com/OpenCover/opencover/. Now you can execute the test using Open cover, which can be using following command.(Line breaks added for readability)
Here is the screenshot of opencover - running on dotnet code application.
Happy Programming :)
What do you think? I would like to hear your thoughts, suggestions, and questions in the comments section below.