Collect human-readable code coverage report for .net core apps

In this post, I will note down steps to collect human-readable code coverage for .net core/standard apps on the developer machine.

Big Picture of Code coverage collection.

I have created a simple .NET standard class library and .net core test project (xUnit) project here.

Project structure: .NET standard class library and xUnit test project


You will require the following NuGet packages to be installed on the xUnit tests project (BeingCraftsman.CoverageDemo.Tests).

  • Microsoft.NET.Test.Sdk (Preinstalled as a part of xUnit tests project)
  • xunit (Preinstalled as a part of xUnit tests project)
  • xunit.runner.visualstudio (Preinstalled as a part of xUnit tests project)
  • coverlet.msbuild
    Install it using the command:
    dotnet add package coverlet.msbuild
  • ReportGenerator
    Install it using the following two commands:
    dotnet new tool-manifest
    dotnet tool install dotnet-reportgenerator-globaltool


  • Open Powershell and navigate to the tests project directory (In my case, BeingCraftsman.CoverageDemo.Tests).
  • Check if the command dotnet test is running all tests.
  • Collect the coverage in a folder (./CodeCoverage in my case) and mention the format opencover.
    WHY opencover?
    ReportGenerator will generate a human-readable report but for that, it requires raw code coverage file in OpenCover format.
    dotnet test /p:CollectCoverage=true /p:CoverletOutput="./CodeCoverage/" /p:CoverletOutputFormat="opencover"
  • Convert opencover format to web pages (Human readable one).
    dotnet reportgenerator "-reports:.\CodeCoverage/coverage.opencover.xml" "-targetdir:.\CodeCoverage\Web"
  • Open generated report
    start .\CodeCoverage\Web\index.htm

Human readable code coverage report giving insights about class, methods etc…

Getting tired of running all these commands one by one.
Next time, onwards, just combine them with “;” separated and execute.

dotnet test /p:CollectCoverage=true /p:CoverletOutput="./CodeCoverage/" /p:CoverletOutputFormat="opencover"; dotnet reportgenerator "-reports:.\CodeCoverage/coverage.opencover.xml" "-targetdir:.\CodeCoverage\Web"; start .\CodeCoverage\Web\index.htm

Brief description of tools/commands:

dotnet test

The dotnet test command is used to execute unit tests in a given solution. The dotnet test command builds the solution and runs a test host application for each test project in the solution.

More details:


Coverlet is Cross platform code coverage for .NET. How it works.

Coverlet also integrates with the build system to run code coverage after tests. In our case, MSBuild is the build system and hence we are using this package. For other build systems, you would require another package.

More details:


ReportGenerator converts coverage reports generated by OpenCover, dotCover, Visual Studio, NCover, Cobertura, JaCoCo, Clover, gcov or lcov into human readable reports in various formats.

More details:

Fizz-Buzz generator using test driven development

Photo by Kevin Grieve on Unsplash

This is a Fizz Buzz generator using test driven development.

Problem statement:

The Fizz buzz generator is a simple program, it’s method say generate accepts the numeric input and produces the output string based on the rules and input number.


The generate method returns the string

  • FizzBuzz when input parameter is divisible by 3 and 5.
  • Fizz when input parameter is divisible by 3.
  • Buzz when input parameter is divisible by 5.
  • String representation of given number when input parameter neither divisible by 3 or 5.

It is clear that there are four use cases to implement

  • FizzBuzz As a fizz buzz generator, I should be able to generate a string FizzBuzz for a given input number when the number is divisible by 3 and 5.
  • Fizz As a fizz buzz generator, I should be able to generate a string Fizz for a given input number when the number is divisible by 3.
  • Buzz As a fizz buzz generator, I should be able to generate a string Buzz for a given input number when the number is divisible by 5.
  • Number (converted to stringAs a fizz buzz generator, I should be able to generate a string format of input number for a given input number when number is neither divisible by 3 or 5.

Visit the github repository fizz-buzz-generator for TDD implementation.

Don’t forget to go through commit by commit to witness the test driven development journey.

Writing test for translation files

In the past, I had worked on different websites and app that support localization.  The user on these sites can work with the language of their choice and translations were provided on UI elements for selected languages.

When working with translation files for multiple languages, I found that there were instances when developers added translation text for English but forget to add translation text for languages other than English. That was a problem when a user chooses to work with a language other than English (He/she was provided with misleading text).

Secondly, there were issues due to duplicate translation keys provided by developers. It leads to incorrect translation due to overwriting (Misleading!).

I learned that adding the test for verifying these rules will help developers to identify the problems before pushing changes to production.

The simple react application is hosted on github:

This sample app has support for English and Hindi language. The app has tests for verifying the translation files.

When the translation keys are present in the all translation files. The test runner display everything is well.

When I add translations in one language file and forgot to add it to another language file, tests start yelling at me.

Thus, the tests for translation files can help the developer to identify the issues related to translation files in development phase itself.