Romanx / Cake.Coverlet

Coverlet extensions for Cake Build
MIT License
40 stars 15 forks source link

No coverage generated with dotnet 7 SDK #55

Closed taconaut closed 1 year ago

taconaut commented 1 year ago

Hi,

Since upgrading Visual Studio 17.4 which in turn installed dotnet 7 SDK along with MSBuild 17.4, coverlet reports are not being generated, respectively saved. Not sure if dotent, msbuild, coverlet or cake.coverlet is at cause here. Before the VS update everything has been working fine.

Installed versins:

Below, the relevant parts of cake.build

var _testOutputDir = MakeAbsolute(Directory("./test-output"));
var _testCoverageResultsDir = MakeAbsolute(_testOutputDir.Combine(Directory("coverage-results")));
var _testResultsDir = MakeAbsolute(_testOutputDir.Combine(Directory ("test-results")));

Task("Build")
    .IsDependentOn("Clean")
    .IsDependentOn("Restore-NuGet-Packages")
    .Does(() => {
        DotNetBuild(
            _solutionPath,
            new DotNetBuildSettings{
                NoRestore = true,
                Configuration = _configuration
            }
        );
        Information($"Finished building solution '{_solutionPath}'.");
    });

Task("Unit-Test")
    .IsDependentOn("Build")
    .Does (() => {
        RunTests(GetFiles($"./**/{_applicationBaseName}*.Tests.Unit.csproj"));
    });

Task("Integration-Test")
    .IsDependentOn("Build")
    .Does (() => {
        RunTests(GetFiles($"./**/{_applicationBaseName}*.Tests.Integration.csproj"));
    });

Task("Test")
    .IsDependentOn("Build")
    .IsDependentOn("Unit-Test")
    .IsDependentOn("Integration-Test");

var _testSettings = new DotNetTestSettings {
    NoBuild = true,
    NoRestore = true,
    Configuration = _configuration,
    ResultsDirectory = _testResultsDir
};

var _coverletSettings = new CoverletSettings {
    CollectCoverage = true,
    CoverletOutputFormat = CoverletOutputFormat.cobertura,
    CoverletOutputDirectory = _testCoverageResultsDir,
    Exclude = new List<string> { "[xunit*]*", $"[*{_applicationBaseName}.Tests.*]*" },
    Include = new List<string> { $"[*{_applicationBaseName}*]*" }
};

private void RunTests(FilePathCollection projectFiles){
    foreach(var projectFile in projectFiles)
    {
        var projectFilePath = projectFile.Segments.Last();

        // Test result customization
        var testResultFileName = $"test-results-{projectFilePath}.xml";
        _testSettings.ArgumentCustomization = args => args.Append($"--logger:trx;LogFileName={testResultFileName}");

        // Coverage result customization
        var coverageResultFileName = $"coverage-results-{projectFilePath}.cobertura.xml";
        _coverletSettings.CoverletOutputName = coverageResultFileName;

        DotNetTest(projectFile.FullPath, _testSettings, _coverletSettings);
    }
}

Which generates the dotnet command:

"C:/Program Files/dotnet/dotnet.exe" test "D:/Dev/Infrastructure.LogAggregator/Source/Infrastructure.LogAggregator.Tests.Integration/Infrastructure.LogAggregator.Tests.Integration.csproj" --configuration Release --no-build --no-restore --results-directory "D:/Dev/Infrastructure.LogAggregator/Source/test-output/test-results" --logger:trx;LogFileName=test-results-Infrastructure.LogAggregator.Tests.Integration.csproj.xml /property:CollectCoverage=True /property:CoverletOutputFormat=\"cobertura\" /property:CoverletOutput="D:/Dev/Infrastructure.LogAggregator/Source/test-output/coverage-results/coverage-results-Infrastructure.LogAggregator.Tests.Integration.csproj.cobertura.xml" /property:Include=\"[*Infrastructure.LogAggregator*]*\" /property:Exclude=\"[xunit*]*,[*Infrastructure.LogAggregator.Tests.*]*\"

with results

Passed! - Failed: 0, Passed: 2, Skipped: 1, Total: 3, Duration: 7 ms - Infrastructure.LogAggregator.Tests.Integration.dll (net6.0) Finished executing task: Integration-Test Completed in 00:00:03.7075473

Task Duration

Clean 00:00:00.0918885 Restore-NuGet-Packages 00:00:00.7450063 Build 00:00:01.5529311 Integration-Test 00:00:03.7079160

Total: 00:00:06.0977419

The test result file ".\test-output\test-results\test-results-Infrastructure.LogAggregator.Tests.Integration.csproj.xml" is being generated but the coverage file, which should have been saved to .\test-output\coverage-results\ are missing (this worked fine before the VS update).

Any idea what's going on? If I have to change something on my side?

Btw I encounter other issues related to build automation since the VS update.

Romanx commented 1 year ago

Hi there, is there any way you could create a small repo project for us to debug this?

taconaut commented 1 year ago

Hi @Romanx, sure, I've set it up here: https://github.com/taconaut/MissingCoverageReport-Cake.Coverlet.MRE On windows, run .\build.ps1 --target=test in the root dir.

I made sure it generates coverage report on a not update machine, which it did.

Unit-Test output, including the coverlet output (which is missing after the VS 17.4 update): image

On the updated (work) machine it looks like this: image

taconaut commented 1 year ago

After mhaving done some digging in the coverlet issues, this seems to be a donet bug https://github.com/coverlet-coverage/coverlet/issues/1391