Describe the bug
When my project includes an extension block which contains a method with an argument with a default value, the project builds and tests pass, but the output coverage.cobertura.xml file is empty.
To Reproduce
With this code in the target project:
extension(LogLevel level)
{
// real implementation does more, obviously, but this is sufficient to reproduce the problem
public static LogLevel Parse(string? logLevel, LogLevel defaultLogLevel = LogLevel.Information) =>
LogLevel.Information;
}
coverage.cobertura.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<coverage line-rate="0" branch-rate="0" version="1.9" timestamp="1787695450" lines-covered="0" lines-valid="0" branches-covered="0" branches-valid="0">
<sources />
<packages />
</coverage>
Whereas if I remove the default value for defaultLogLevel:
extension(LogLevel level)
{
// real implementation does more, obviously, but this is sufficient to reproduce the problem
public static LogLevel Parse(string? logLevel, LogLevel defaultLogLevel) =>
LogLevel.Information;
}
I get detailed information in coverage.cobertura.xml
<?xml version="1.0" encoding="utf-8"?>
<coverage line-rate="1" branch-rate="0.8887999999999999" version="1.9" timestamp="1787695430" lines-covered="51" lines-valid="51" branches-covered="16" branches-valid="18">
...snip
Expected behavior
Full coverage results are produced even if methods in extension blocks contain default values for arguments.
Actual behavior
Coverage results are empty when extension blocks contain default values for arguments.
Configuration:
Test project csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<AnalysisMode>Recommended</AnalysisMode>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="10.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.9.0" />
<PackageReference Include="NUnit" Version="4.6.1"/>
<PackageReference Include="NUnit.Analyzers" Version="4.14.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" Version="6.3.0" />
</ItemGroup>
<ItemGroup>
<Using Include="NUnit.Framework"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="<cool target project>.csproj"/>
</ItemGroup>
</Project>
Additional context
I am on Ubuntu 24.04, with .NET SDK 10.0.302. I have not tried to reproduce on Windows or MacOS, but we do see the same failure to generate coverage reports on GitHub Actions runners.
Describe the bug
When my project includes an extension block which contains a method with an argument with a default value, the project builds and tests pass, but the output
coverage.cobertura.xmlfile is empty.To Reproduce
With this code in the target project:
coverage.cobertura.xmllooks like this:Whereas if I remove the default value for
defaultLogLevel:I get detailed information in
coverage.cobertura.xmlExpected behavior
Full coverage results are produced even if methods in extension blocks contain default values for arguments.
Actual behavior
Coverage results are empty when extension blocks contain default values for arguments.
Configuration:
Test project
csproj:Additional context
I am on Ubuntu 24.04, with .NET SDK 10.0.302. I have not tried to reproduce on Windows or MacOS, but we do see the same failure to generate coverage reports on GitHub Actions runners.