0

I've got a project (say A.csproj) and a tests project (say T.csproj).

T has coverlet.msbuild and Microsoft.NET.Test.Sdk as nuget references. T has a .runsettings file with no include include/exclude paths (all assemblies included, non excluded).

Doing dotnet test T.csproj /p:CollectCoverage=true /p:IncludeTestAssembly=true /p:CoverletOutputFormat=cobertura --settings:".runsettings", results in only coverage being generated for the tests project:

+--------------------+--------+--------+--------+
| Module             | Line   | Branch | Method |
+--------------------+--------+--------+--------+
| T                  | 98.87% | 100%   | 96.29% |
+--------------------+--------+--------+--------+

+---------+--------+--------+--------+
|         | Line   | Branch | Method |
+---------+--------+--------+--------+
| Total   | 98.87% | 100%   | 96.29% |
+---------+--------+--------+--------+
| Average | 98.87% | 100%   | 96.29% |
+---------+--------+--------+--------+

If I drop /p:IncludeTestAssembly=true, there's only an empty report generated:

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

+---------+------+--------+--------+
|         | Line | Branch | Method |
+---------+------+--------+--------+
| Total   | 0%   | 0%     | 0%     |
+---------+------+--------+--------+
| Average | 0%   | 0%     | 0%     |
+---------+------+--------+--------+

The same happens even when I specify for inclusion for all modules via the cmdline itself: dotnet test T.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:Include="[*]*"

Contents of T.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <!--<IsPackable>false</IsPackable>-->

  <PropertyGroup>
    <ProduceReferenceAssembly>false</ProduceReferenceAssembly>
    <GenerateDocumentationFile>false</GenerateDocumentationFile>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="coverlet.collector" Version="3.1.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="coverlet.msbuild" Version="3.1.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
    <PackageReference Include="Moq" Version="4.18.1" />
    <PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
    <PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\E2EPoC.Specs\E2EPoC.Specs.csproj" />
  </ItemGroup>

</Project>
Artur INTECH
  • 6,024
  • 2
  • 37
  • 34
hexcode
  • 393
  • 1
  • 4
  • 13

1 Answers1

0

Try this:

$>src> dotnet test <YOUR_PROJECT>.sln --no-build /p:CollectCoverage=true /p:CoverletOutput=..\results\coverage /p:MergeWith=..\results\coverage.json /p:CoverletOutputFormat=opencover
$>src> reportgenerator -reports:**/coverage.opencover.xml -targetdir:Tests\results\WebResult
$>src> Tests\results\WebResult\index.html
Felipe Augusto
  • 1,341
  • 1
  • 16
  • 18