.NET Core coverage with coverlet

#static-analysis #code-coverage

At work we work mainly with Microsoft technologies, so I’m being exposed to things like C#, .NET Core, .NET Framework, Azure, etc. So I’m vesting more time learning tools and processes around Microsoft tools. This post is a kind of recipe to get started into .NET Core 3.1 with coverage and SonarQube to keep track of metrics.

Pre-requisites

First of all I consider that…

  • You have .NET Core 3.1 installed
  • Docker way: you will need Docker installed, Docker Desktop or Docker Machine if you do not have Windows Pro
  • Java way: we will install Java 11+ (so do not worry) to run SonarQube on top of Windows

Create the project

Let’s start by creating two projects: the program itself and the test one. Then we create a solution file (sln), add both projects and reference the program from the test project: