Code Coverage Made Simple — An Introduction to dotCover

Alexander Obregon
3 min readJul 6, 2023

--

Image Source

Introduction

In the dynamic world of software development, ensuring the quality and reliability of your code is crucial. Code coverage is a measure that tells you how much of your code is being executed during testing. Understanding code coverage can provide insights into the areas of your code that need more thorough testing. One such tool that helps in analyzing code coverage for .NET applications is JetBrains dotCover. In this article, we will dive into dotCover, explore its features and understand how it can be beneficial for .NET developers.

What is dotCover?

JetBrains dotCover is a .NET unit test runner and code coverage tool that works with ReSharper in Visual Studio. It analyzes code coverage for test cases in .NET applications and provides visual reports. With dotCover, you can ensure that every section of your code is tested, and identify parts of the code that are not covered by test cases, which might be vulnerable to bugs or other issues.

Getting Started with dotCover

Before using dotCover, make sure that you have Visual Studio installed on your machine. Follow these steps to install and set up dotCover:

  1. Navigate to the JetBrains website and download dotCover.
  2. Install dotCover as a separate application or as a part of the ReSharper Ultimate suite.
  3. Once installed, open Visual Studio. You’ll notice a new dotCover menu in the toolbar.
  4. Now you are ready to analyze your code coverage!

Analyze Code Coverage

To analyze code coverage using dotCover, follow these steps:

  1. Open the solution you want to analyze in Visual Studio.
  2. In the dotCover menu, select “Cover Unit Tests”.
  3. dotCover will run the tests and analyze the code coverage.
  4. Once completed, the results will be displayed in a Coverage Results tab.

Understanding the Code Coverage Results

dotCover’s Coverage Results tab provides a comprehensive view of the code coverage in your application. Here’s how to interpret the data:

  • Coverage Tree: This shows the structure of your solution in a tree format. You can see the percentage of code covered by tests for each project, namespace, class, and method.
  • Coverage Area: This provides a graphical representation of code coverage. Green signifies covered code, and red signifies uncovered code.
  • Code Preview: You can click on any class or method to view the source code. Covered code lines are highlighted in green, and uncovered lines in red.

Continuous Testing Mode

One of the prominent features of dotCover is Continuous Testing. In this mode, dotCover runs tests automatically when you change the code. This helps in obtaining instant feedback on how your changes affect the code coverage.

To enable Continuous Testing Mode:

  1. Go to the dotCover menu in Visual Studio.
  2. Select “Continuous Testing” and choose “Session | Start”.
  3. dotCover will now run tests automatically whenever you make changes to your code.

Integrating with TeamCity

For teams that rely on Continuous Integration, dotCover can be seamlessly integrated with JetBrains TeamCity. This allows you to keep track of code coverage statistics over time and ensure that the team meets its quality goals.

To integrate dotCover with TeamCity:

  1. Open your TeamCity project settings.
  2. Navigate to Build Steps and add a build step with Runner type as “dotCover”.
  3. Configure the dotCover settings as per your requirements.
  4. Run the build in TeamCity, and you’ll see the code coverage report in the build results.

Pros and Cons

Pros:

  • Seamless integration with Visual Studio and ReSharper.
  • Continuous Testing Mode for real-time feedback.
  • Detailed code coverage reports.

Cons:

  • Available only for .NET applications.
  • Might have performance impacts on larger solutions.

Conclusion

JetBrains dotCover is an essential tool for .NET developers who want to improve the quality of their code through rigorous testing. Its seamless integration with Visual Studio, coupled with the Continuous Testing mode, makes it incredibly convenient to keep track of what portions of the code are being tested. Although it is tailored for .NET applications and can have performance issues on larger solutions, the benefits it brings to the table make it an invaluable asset for any .NET development team.

So, whether you are an individual developer or part of a larger team, give dotCover a try and take a step towards writing more reliable and strong .NET applications!

  1. JetBrains dotCover Documentation
  2. JetBrains dotCover Blog

--

--

Alexander Obregon

Software Engineer, fervent coder & writer. Devoted to learning & assisting others. Connect on LinkedIn: https://www.linkedin.com/in/alexander-obregon-97849b229/