question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to exclude test assemblies

See original GitHub issue

Shouldn’t test assemblies be excluded by default according to #618 or did something change?

In any case, I tried to exclude test assemblies by setting the IncludeTestAssembly flag to false but some test assemblies still appear in the code coverage report. What may be the issue?

Here is the .runsettings file:

<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
  <DataCollectionRunSettings>
    <DataCollectors>
      <DataCollector friendlyName="XPlat code coverage">
        <Configuration>
          <Format>cobertura,opencover</Format>          
          <ExcludeByAttribute>Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute,TestSDKAutoGeneratedCode</ExcludeByAttribute>
          <IncludeTestAssembly>false</IncludeTestAssembly>
        </Configuration>
      </DataCollector>
    </DataCollectors>
  </DataCollectionRunSettings>
</RunSettings>

The command I’m using is dotnet test --collect:"XPlat Code Coverage" --settings coverlet.runsettings

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
MarcoRossignolicommented, Jan 16, 2022

Closing for stale conversation, feel free to reopen if needed.

1reaction
JohnLudlowcommented, Nov 15, 2021

@MarcoRossignoli Apologies for the delay here. I tried to make a repro sample, and didn’t get the same behaviour.

Our production code is a mix of .NET Framework and .NET Core, and I think one test assembly was being run as a .NET Framework test with vstest.console but it was a .NET Core test so that might have confused things. Also, it’s possible that the Azure DevOps plugins pass different defaults than the tools do locally, so I’m working on an MSBuild proj for the pipeline to call.

I’ll let you know if I run into more issues as I progress

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to exclude test assemblies from VS code coverage?
The answer is here - https://learn.microsoft.com/en-us/visualstudio/test/customizing-code-coverage-analysis?view=vs-2019 and here ...
Read more >
Customizing Code Coverage Analysis - Visual Studio
To exclude test code from the code coverage results and only include application code, add the ExcludeFromCodeCoverageAttribute attribute to ...
Read more >
Need to exclude a Particular Test Method from Build ...
If you are running the pipeline with the “Test assemblies” option, please try the Test filter critera input. It could filter the tests...
Read more >
Excluding Your .NET Test Project From Code Coverage
Include the code below in a Directory.Build.props file at the root of your tests folder, where all your projects are located. The configuration ......
Read more >
Including and Excluding Assemblies from Code Coverage
What I want to do is exclude the test assemblies from the coverage numbers, but the ExcludeFromCodeCoverageAttribute can't be applied to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found