如何从Cake获取TeamCity中的DotCover覆盖率

时间:2017-09-30 02:37:49

标签: teamcity dotcover cakebuild

我最近采用了构建工具Cake,但我很难获得在TeamCity中显示的DotCover单元测试覆盖率报告。

我已尝试过以下任务:

Task("Run-Regression-Tests")
    .IsDependentOn("Build")
    .Does(() =>
{
    var resultPath = artifactsDirectory + File("results.dcvr");
    DotCoverCover(tool => 
        {
            tool.NUnit3(new[] {
                "./Foo.UnitTests/bin/" + configuration + "/Foo.UnitTests.dll",
                "./Bar.UnitTests/bin/" + configuration + "/Bar.UnitTests.dll",
                "./Baz.IntegrationTests/bin/" + configuration + "/Baz.IntegrationTests.dll"
            }, new NUnit3Settings {
                NoResults = true
            });
        },
        resultPath,
        new DotCoverCoverSettings()
            .WithFilter("+:Foo.Domain"));

    TeamCity.ImportDotCoverCoverage(resultPath);
});

但是,这会产生TeamCity的以下输出:

// Output immediately after unit test success report:

[03:01:52][Step 1/1] [JetBrains dotCover] Coverage session finished [30/09/2017 03:01:52]
[03:01:52][Step 1/1] [JetBrains dotCover] Coverage results post-processing started [30/09/2017 03:01:52]
[03:01:53][Step 1/1] [JetBrains dotCover] Coverage results post-processing finished [30/09/2017 03:01:53]
[03:01:53][Step 1/1] 
[03:01:53][Step 1/1] ========================================
[03:01:53][Step 1/1] Create Octopus Release
[03:01:53][Step 1/1] ========================================
[03:01:53][Step 1/1] Importing data from 'artifacts/results.dcvr' (7.49 MB) with 'dotNetCoverage' processor

// After cake finishes:

[03:02:11]Waiting for 1 service processes to complete
[03:02:11]Processing 1 coverage report(s)
[03:02:11]Generating coverage report by dotcover for files: [C:\TeamCity\buildAgent\work\47e2e68a6c48ce48\artifacts\results.dcvr]
[03:02:11]Get dotCover version (1s)
[03:02:13]Use DotCover 2016 and higher commands set
[03:02:13]Merge dotCover reports
[03:02:14][Merge dotCover reports] Started dotCover: C:\TeamCity\buildAgent\tools\dotCover\dotCover.exe merge C:\TeamCity\buildAgent\temp\buildTmp\dotcover4470082908956100659.xml
[03:02:14]
[Merge dotCover reports] Output: JetBrains dotCover Console Runner 2017.1.1. Build 108.0.20170407.130252
Copyright (c) 2009-2017 JetBrains s.r.o. All rights reserved.
[JetBrains dotCover] Snapshot merging started [30/09/2017 03:02:13]
[JetBrains dotCover] Source snapshots number: 1
[03:02:14][Merge dotCover reports] [JetBrains dotCover] Failed to merge snapshots. Set of standalone sections doesn't comply ReverseFunctionCoverageSnapshotDataDescriptor specification. Set of standalone sections doesn't comply ReverseFunctionCoverageSnapshotDataDescriptor specification
[03:02:14]
[Merge dotCover reports] 
[03:02:14][Merge dotCover reports] dotCover exited with code: -2
[03:02:14][Merge dotCover reports] dotCover returned non-zero exit code.
[03:02:14]Remove dotCover snapshot files
[03:02:14]Generate dotCover report
[03:02:15][Generate dotCover report] Started dotCover: C:\TeamCity\buildAgent\tools\dotCover\dotCover.exe report C:\TeamCity\buildAgent\temp\buildTmp\dotcover1750892168641886115.xml
[03:02:15]
[Generate dotCover report] Output: JetBrains dotCover Console Runner 2017.1.1. Build 108.0.20170407.130252
Copyright (c) 2009-2017 JetBrains s.r.o. All rights reserved.
[03:02:15][Generate dotCover report] [JetBrains dotCover] Report source "C:\TeamCity\buildAgent\temp\buildTmp\dotCover1103887209553630063Merge" doesn't exist. 
[03:02:15]
[Generate dotCover report] 
[03:02:15][Generate dotCover report] dotCover exited with code: -2
[03:02:15][Generate dotCover report] dotCover returned non-zero exit code.
[03:02:15]Generate dotCover HTML report
[03:02:15]Packing snapshot files
[03:02:15][Packing snapshot files] Started dotCover: C:\TeamCity\buildAgent\tools\dotCover\dotCover.exe zip C:\TeamCity\buildAgent\temp\buildTmp\dotcover5049141835197969589.xml
[03:02:15]
[Packing snapshot files] Output: JetBrains dotCover Console Runner 2017.1.1. Build 108.0.20170407.130252
Copyright (c) 2009-2017 JetBrains s.r.o. All rights reserved.
[03:02:15][Packing snapshot files] [JetBrains dotCover] Source file doesn't exist. 

似乎TeamCity正在尝试合并dotcover快照,但我不认为我告诉它。我发现在部署到章鱼任务开始后上传artifacts / results.dcvr也很奇怪

我尝试过使用DotCoverAnalyze,结果路径为" result.xml"但是TeamCity报告它是一种无效的文件格式。

那么,您如何使用cake和TeamCity收集和导入DotCover报道?

1 个答案:

答案 0 :(得分:6)

这就是我目前将dotCover覆盖率报告导入TeamCity的方法。请注意我如何给DotCover.exe主目录提供绝对路径以覆盖捆绑的DotCover.exe。当捆绑的DotCover版本与您使用Cake的版本(例如,.\tools文件夹中的版本之一)不兼容时,这可能很有用。

Task("Run-Unit-Tests")
    .IsDependentOn("Build")
    .Does(() =>
{
    DotCoverCover((ICakeContext c) => {
            c.NUnit3("./src/**/bin/x64/" + parameters.Configuration + "/Foo.Test.dll",
                new NUnit3Settings
                {
                    Results = parameters.Paths.TestResult,
                    TeamCity = parameters.IsTeamCity
                }
            );
        },
        parameters.Paths.CoverageResult,
        new DotCoverCoverSettings()
            .WithFilter("+:Foo")
            .WithFilter("-:Foo.Test"));
})
.Finally(() =>
{
    if(parameters.IsTeamCity)
    {
        TeamCity.ImportData("nunit", parameters.Paths.TestResult);
        TeamCity.ImportDotCoverCoverage(
            parameters.Paths.CoverageResult,
            MakeAbsolute(Directory("./tools/JetBrains.dotCover.CommandLineTools/tools")));
    }
    else
    {
        DotCoverReport(
            parameters.Paths.CoverageResult,
            parameters.Paths.CoverageResult.ChangeExtension("html"),
            new DotCoverReportSettings
            {
                ReportType = DotCoverReportType.HTML
            });
    }
});