

NET standard class library using the dotnet new classlib command: dotnet new classlib -n Numbers Create a class libraryįrom a command prompt in a new directory named UnitTestingCodeCoverage, create a new. For this article, you'll create a class library that will be the system under test, and two corresponding unit test projects. The "system under test" refers to the code that you're writing unit tests against, this could be an object, service, or anything else that exposes testable functionality. This article is based on the sample source code project, available on samples browser. ReportGenerator converts coverage reports generated by Cobertura among many others, into human-readable reports in various formats. The report generation is possible using another open source project on GitHub - ReportGenerator. Coverlet collects Cobertura coverage test run data, which is used for report generation.Īdditionally, this article details how to use the code coverage information collected from a Coverlet test run to generate a report. Coverlet is an open source project on GitHub that provides a cross-platform code coverage framework for C#. While this article focuses on C# and xUnit as the test framework, both MSTest and NUnit would also work. This article discusses the usage of code coverage for unit testing with Coverlet and report generation using ReportGenerator. As an example, if you have a simple application with only two conditional branches of code ( branch a, and branch b), a unit test that verifies conditional branch a will report branch code coverage of 50%. Code coverage is a measurement of the amount of code that is run by unit tests - either lines, branches, or methods.

Unit tests help to ensure functionality and provide a means of verification for refactoring efforts. If you already have a project, you can skip ahead to the Code coverage tooling section. This article explains the creation of the example project.
