Xml 通过Cake构建脚本报告.NET核心XUnit测试,以便Azure DevOps可以使用它

Xml 通过Cake构建脚本报告.NET核心XUnit测试,以便Azure DevOps可以使用它,xml,.net-core,azure-devops,xunit.net,cakebuild,Xml,.net Core,Azure Devops,Xunit.net,Cakebuild,我试图报告Azure DevOps中.NET核心XUnit项目的XUnit结果。构建过程是在由Azure DevOps构建管道调用的Cake构建脚本中编写的。XUnit测试运行,但它们只向CLI报告最小值。我希望将摘要和详细信息写入一个文件:JSON、XML,这并不重要。以下是当前的示例代码: Task("UnitTests") .Does(() => { DotNetCoreTest( testProject,

我试图报告Azure DevOps中.NET核心XUnit项目的XUnit结果。构建过程是在由Azure DevOps构建管道调用的Cake构建脚本中编写的。XUnit测试运行,但它们只向CLI报告最小值。我希望将摘要和详细信息写入一个文件:JSON、XML,这并不重要。以下是当前的示例代码:

Task("UnitTests")
    .Does(() =>
    {
        DotNetCoreTest(
            testProject,
            new DotNetCoreTestSettings()
            {
                Configuration = configuration,
                NoBuild = true
            }
        );
    });
Cake脚本由Powershell脚本通过构建管道中的Powershell任务运行

要在Cake中运行dotnetcoretest,使其报告到我可以使用Azure DevOps的格式和位置,我需要做什么?我尝试使用“-xml”参数,但这对dotnet测试不起作用

我是否必须在Azure DevOps中的构建管道中添加任务才能从Cake脚本中获取XUnit结果


如何在Azure DevOps中查看XUnit测试?

您可以以VSTest格式导出

Task("UnitTests")
    .Does(() =>
    {
        DotNetCoreTest(
            testProject,
            new DotNetCoreTestSettings()
            {
                Configuration = configuration,
                NoBuild = true,
                NoRestore = true,
                ArgumentCustomization = args=>args.Append($"--logger trx;LogFileName=\"{testResultsFile}\"")
            }
        );
    });
然后,您可以在Azure DevOps中添加类似的任务

亚马尔 设计师

蛋糕 或者直接从蛋糕脚本使用


仅供参考,我使用Cake方法发布测试结果,效果很好。
    steps:
    - task: PublishTestResults@2
      displayName: 'Publish Test Results artifacts/**/test-results/*TestResults*.xml'
      inputs:
        testResultsFormat: VSTest
        testResultsFiles: 'artifacts/**/test-results/*TestResults*.xml'
TFBuild.Commands.PublishTestResults(
    new TFBuildPublishTestResultsData {
        TestResultsFiles = new []{
            testResultsFile
        },
        TestRunner = TFTestRunnerType.VSTest
    }
)