Code coverage can be automatically collected and displayed after running tests in the Test Explorer window in Visual Studio.

This feature is supported in Visual Studio 2019 and 2022.

In Visual Studio 2019, only .NET Framework projects are supported. Shared projects are not supported.

  1. Enable the Enable Code Coverage option in the Visual Studio toolbar.
  2. Run the tests in the Test Explorer view.
    The coverage will be automatically displayed in the Coverage view.
  3. See Viewing Coverage for details about viewing coverage data.