未验证 提交 85bfbfcf 编写于 作者: V Viktor Hofer 提交者: GitHub

Re-enable xunit.console code coverage (#35894)

Re-enable xunit console code coverage measurement until
https://github.com/coverlet-coverage/coverlet/issues/834 is fixed.
上级 5eaac684
......@@ -2,8 +2,14 @@
"version": 1,
"isRoot": true,
"tools": {
"coverlet.console": {
"version": "1.7.1",
"commands": [
"coverlet"
]
},
"dotnet-reportgenerator-globaltool": {
"version": "4.5.2",
"version": "4.5.8",
"commands": [
"reportgenerator"
]
......
......@@ -36,7 +36,7 @@ This runs the tests and generates the full code coverage report. The resulting i
You can also build and test with code coverage for a particular test project rather than for the whole repo with the `/p:Coverage=true` property:
dotnet test -f net5.0 /p:Coverage=true
dotnet build /t:Test /p:Coverage=true
The results for this one library will then be available in this index.htm file, where $(OutDir) is the directory where the binaries were generated.
......@@ -44,7 +44,7 @@ The results for this one library will then be available in this index.htm file,
For example, to build, test, and get code coverage results for the System.Diagnostics.Debug library, from the root of the repo one can do:
dotnet test src\libraries\System.Diagnostics.Debug -f net5.0 /p:Coverage=true
dotnet build src\System.Diagnostics.Debug\tests /t:Test /p:Coverage=true
And then once the run completes:
......
......@@ -33,8 +33,32 @@
</PropertyGroup>
</Target>
<!-- TODO remove when https://github.com/coverlet-coverage/coverlet/issues/834 is fixed. -->
<Target Name="AddCoverageCommand"
BeforeTargets="GenerateRunScript"
DependsOnTargets="SetupCoverageFilter"
Condition="'$(Coverage)' == 'true'">
<PropertyGroup>
<CoverageOutputPath Condition="'$(CoverageOutputPath)' == ''">coverage.opencover.xml</CoverageOutputPath>
<CoverageReportInputPath Condition="'$(CoverageReportInputPath)' == ''">$(CoverageOutputPath)</CoverageReportInputPath>
<CoverageReportDir Condition="'$(CoverageReportDir)' == ''">$([MSBuild]::NormalizeDirectory('$(OutDir)', 'report'))</CoverageReportDir>
<RunScriptCommand>"$(DotNetTool)" tool run coverlet "$(TargetFileName)" --target "$(RunScriptHost)" --targetargs "$(RunScriptCommand.Replace('&quot;$(RunScriptHost)&quot;', ''))" --format "opencover" --output "$(CoverageOutputPath)" --verbosity "normal" --use-source-link</RunScriptCommand>
<RunScriptCommand Condition="'@(CoverageExcludeByFile)' != ''">$(RunScriptCommand) --exclude-by-file @(CoverageExcludeByFile -> '"%(Identity)"', ' --exclude-by-file ')</RunScriptCommand>
<RunScriptCommand Condition="'@(CoverageIncludeDirectory)' != ''">$(RunScriptCommand) --include-directory @(CoverageIncludeDirectory -> '"$(RunScriptHostDir)%(Identity)"', ' --include-directory ')</RunScriptCommand>
<RunScriptCommand>$(RunScriptCommand) --include @(CoverageInclude -> '"[%(Identity)]*"', ' --include ')</RunScriptCommand>
<CoverageReportCommandLine>"$(DotNetTool)" tool run reportgenerator "-reports:$(CoverageReportInputPath)" "-targetdir:$(CoverageReportDir.TrimEnd('\/'))" "-reporttypes:Html" "-verbosity:Info"</CoverageReportCommandLine>
</PropertyGroup>
<!-- Skip generating individual reports if a full report is generated. -->
<ItemGroup Condition="'$(BuildAllProjects)' != 'true' and '$(SkipCoverageReport)' != 'true'">
<PostRunScriptCommands Include="$(CoverageReportCommandLine)" />
</ItemGroup>
</Target>
<!-- Build a coverage report if building an individual library with Coverage true. -->
<Target Name="GenerateCoverageReport"
Condition="'$(Coverage)' == 'true' and '$(SkipCoverageReport)' != 'true'"
Condition="'$(Coverage)' == 'true' and '$(BuildAllProjects)' != 'true' and '$(SkipCoverageReport)' != 'true'"
AfterTargets="VSTest">
<ItemGroup Condition="'$(CoverageReportInputPath)' == ''">
<CoverageOutputFile Include="$(OutDir)TestResults\*\coverage.opencover.xml" />
......
......@@ -5,7 +5,7 @@
<!-- For tests we want to continue running if a test run failed. -->
<TestContinueOnError>ErrorAndContinue</TestContinueOnError>
<TraversalGlobalProperties>BuildAllProjects=true</TraversalGlobalProperties>
<CoverageReportInputPath>$(ArtifactsBinDir)*.Tests\TestResults\*\coverage.opencover.xml</CoverageReportInputPath>
<CoverageReportInputPath>$(ArtifactsBinDir)\*.Tests\**\coverage.opencover.xml</CoverageReportInputPath>
<CoverageReportDir>$(ArtifactsDir)coverage</CoverageReportDir>
<EnableCoverageSupport>true</EnableCoverageSupport>
</PropertyGroup>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册