.net-corecode-coverage

How to exclude test assemblies from VS code coverage?


So, I generate the code coverage report by running dotnet test --no-build -l trx --collect "Code coverage". Unfortunately, it also computes the code coverage for the test assemblies. How do I tell it not to collect for test assemblies?


Solution

  • The --collect flag is an option for code coverage. If you prefer to work in the CLI, you can exclude projects as follows:

    dotnet test --no-build --collect "Code Coverage;Exclude=[Exclude.Project.*],[Python.*]"
    

    For example, this will exclude all projects with names starting with Exclude.Project and Python.