Skip to content

/p:CollectCoverage=true causes all test discovery to fail when class derives from XUnitVerifier #544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AArnott opened this issue Sep 14, 2019 · 6 comments
Labels
as-designed Expected behaviour

Comments

@AArnott
Copy link
Contributor

AArnott commented Sep 14, 2019

Repro
Unzip: mytestlib.zip
Within the unzipped directory, run:

dotnet test
dotnet test /p:CollectCoverage=true

Notice how the one test method runs successfully the first time. But when code coverage is enabled, no tests are discovered at all.

I suspect an exception is being thrown during the code coverage instrumentation. Perhaps the XunitVerifier class I'm using as a base class (which is required to repro the failure) uses a pattern that coverlet.msbuild can't deal with.

@AArnott
Copy link
Contributor Author

AArnott commented Sep 14, 2019

@sharwell owns the XunitVerifier class I believe.

AArnott added a commit to AArnott/VSSDK-Analyzers that referenced this issue Sep 14, 2019
AArnott added a commit to AArnott/VSSDK-Analyzers that referenced this issue Sep 14, 2019
@MarcoRossignoli MarcoRossignoli added the as-designed Expected behaviour label Sep 16, 2019
@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Sep 16, 2019

Hi @AArnott, yep the issue is the instrumentation of Microsoft.CodeAnalysis.Testing.Verifiers.XUnit.dll
For now you can fix with filters

dotnet test /p:CollectCoverage=true  /p:exclude=\"[Microsoft*]*,[xunit*]*\"
dotnet test /p:CollectCoverage=true  /p:include=\"[mytestlib*]*\"

BTW next release should solve without any action we'll skip non instrumentable dll(embedded or external pdb with no local source), I did a test with master(tomorrow you can use nightly, I just fixed an issue we're back by a week).
Future result will be:

C:\git\coverletissue\mytestlib
λ dotnet test /p:CollectCoverage=true /p:CoverletToolsPath=C:\git\coverlet\src\coverlet.msbuild.tasks\bin\Debug\netstandard2.0\
C:\Users\Marco\.nuget\packages\coverlet.msbuild\2.6.3\build\coverlet.msbuild.targets(24,5): warning : [coverlet] Unable to instrument module: C:\git\coverletissue\mytestlib\bin\Debug\net472\Microsoft.CodeAnalysis.Analyzer.Testing.dll, embedded pdb without local source files, [/_/src/Tools/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/AnalyzerTest`1.cs] [C:\git\coverletissue\mytestlib\mytestlib.csproj]
C:\Users\Marco\.nuget\packages\coverlet.msbuild\2.6.3\build\coverlet.msbuild.targets(24,5): warning : [coverlet] Unable to instrument module: C:\git\coverletissue\mytestlib\bin\Debug\net472\Microsoft.CodeAnalysis.CodeFix.Testing.dll, embedded pdb without local source files, [/_/src/Tools/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing/CodeFixTest`1.cs] [C:\git\coverletissue\mytestlib\mytestlib.csproj]
C:\Users\Marco\.nuget\packages\coverlet.msbuild\2.6.3\build\coverlet.msbuild.targets(24,5): warning : [coverlet] Unable to instrument module: C:\git\coverletissue\mytestlib\bin\Debug\net472\Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.dll, embedded pdb without local source files, [/_/src/Tools/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CSharp.CodeFix.Testing/CSharpCodeFixTest`3.cs] [C:\git\coverletissue\mytestlib\mytestlib.csproj]
C:\Users\Marco\.nuget\packages\coverlet.msbuild\2.6.3\build\coverlet.msbuild.targets(24,5): warning : [coverlet] Unable to instrument module: C:\git\coverletissue\mytestlib\bin\Debug\net472\Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit.dll, embedded pdb without local source files, [/_/src/Tools/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit/CodeFixVerifier.cs] [C:\git\coverletissue\mytestlib\mytestlib.csproj]
C:\Users\Marco\.nuget\packages\coverlet.msbuild\2.6.3\build\coverlet.msbuild.targets(24,5): warning : [coverlet] Unable to instrument module: C:\git\coverletissue\mytestlib\bin\Debug\net472\Microsoft.CodeAnalysis.Testing.Verifiers.XUnit.dll, embedded pdb without local source files, [/_/src/Tools/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Testing.Verifiers.XUnit/XUnitVerifier.cs] [C:\git\coverletissue\mytestlib\mytestlib.csproj]
C:\Users\Marco\.nuget\packages\coverlet.msbuild\2.6.3\build\coverlet.msbuild.targets(24,5): warning : [coverlet] Unable to instrument module: C:\git\coverletissue\mytestlib\bin\Debug\net472\xunit.assert.dll, embedded pdb without local source files, [C:\Dev\xunit\xunit\src\xunit.assert\Asserts\Assert.cs] [C:\git\coverletissue\mytestlib\mytestlib.csproj]
C:\Users\Marco\.nuget\packages\coverlet.msbuild\2.6.3\build\coverlet.msbuild.targets(24,5): warning : [coverlet] Unable to instrument module: C:\git\coverletissue\mytestlib\bin\Debug\net472\xunit.core.dll, embedded pdb without local source files, [C:\Dev\xunit\xunit\src\common\ExceptionExtensions.cs] [C:\git\coverletissue\mytestlib\mytestlib.csproj]
C:\Users\Marco\.nuget\packages\coverlet.msbuild\2.6.3\build\coverlet.msbuild.targets(24,5): warning : [coverlet] Unable to instrument module: C:\git\coverletissue\mytestlib\bin\Debug\net472\xunit.execution.desktop.dll, embedded pdb without local source files, [C:\Dev\xunit\xunit\src\xunit.execution\Extensions\ReflectionAbstractionExtensions.cs] [C:\git\coverletissue\mytestlib\mytestlib.csproj]
C:\Users\Marco\.nuget\packages\coverlet.msbuild\2.6.3\build\coverlet.msbuild.targets(24,5): warning : [coverlet] Unable to instrument module: C:\git\coverletissue\mytestlib\bin\Debug\net472\xunit.runner.reporters.net452.dll, embedded pdb without local source files, [C:\Dev\xunit\xunit\src\xunit.runner.reporters\Utility\EnvironmentHelper.cs] [C:\git\coverletissue\mytestlib\mytestlib.csproj]
C:\Users\Marco\.nuget\packages\coverlet.msbuild\2.6.3\build\coverlet.msbuild.targets(24,5): warning : [coverlet] Unable to instrument module: C:\git\coverletissue\mytestlib\bin\Debug\net472\xunit.runner.utility.net452.dll, embedded pdb without local source files, [C:\Dev\xunit\xunit\src\xunit.runner.utility\Extensions\DisposableExtensions.cs] [C:\git\coverletissue\mytestlib\mytestlib.csproj]
C:\Users\Marco\.nuget\packages\coverlet.msbuild\2.6.3\build\coverlet.msbuild.targets(24,5): warning : [coverlet] Unable to instrument module: C:\git\coverletissue\mytestlib\bin\Debug\net472\xunit.runner.visualstudio.testadapter.dll, embedded pdb without local source files, [C:\Dev\xunit\xunit\src\xunit.runner.visualstudio\Utility\AssemblyExtensions.cs] [C:\git\coverletissue\mytestlib\mytestlib.csproj]
Test run for C:\git\coverletissue\mytestlib\bin\Debug\net472\mytestlib.dll(.NETFramework,Version=v4.7.2)
Microsoft (R) Test Execution Command Line Tool Version 16.2.0-preview-20190606-02
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 1,9011 Seconds

Calculating coverage result...
  Generating report 'C:\git\coverletissue\mytestlib\coverage.json'

+--------+------+--------+--------+
| Module | Line | Branch | Method |
+--------+------+--------+--------+
...

To hide the warning we expect that a user will add excludes, or we could move from warning to verbose.
Feel free to close if solved!

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Sep 16, 2019

I moved from warning to verbose because xunit will warning every time. #548

AArnott added a commit to AArnott/VSSDK-Analyzers that referenced this issue Sep 17, 2019
@AArnott
Copy link
Contributor Author

AArnott commented Sep 17, 2019

Thanks! The exclude workaround worked for me and I'll go with that for now.

@AArnott AArnott closed this as completed Sep 17, 2019
@sharwell
Copy link
Contributor

@MarcoRossignoli Why is it saying there is an embedded PDB without source files? The source files are part of the embedded PDB.

@MarcoRossignoli
Copy link
Collaborator

Maybe the message is not so clear...I mean "embedded pdb without local source files," local is about local hard drive...if sources are not on pc running test we skip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
as-designed Expected behaviour
Projects
None yet
Development

No branches or pull requests

3 participants