【问题标题】:How to run XUnit Tests with Jenkins如何使用 Jenkins 运行 XUnit 测试
【发布时间】:2016-02-15 09:33:44
【问题描述】:

我刚刚开始使用 XUnit 并配置了 Jenkins,我想问一下是否有一种方法可以运行由 Jenkins 直接启动的 XUnit 测试,而不是使用 Windows 批处理命令来启动 XUnit 的控制台运行程序。

我知道有可能通过控制台运行程序执行 Windows 批处理命令来运行 XUnit 测试,但我正在寻找一个插件/例如包含 XUnit 运行程序的任何东西,你只需要指向 dll 所以他启动测试并处理 XML 输出。

【问题讨论】:

    标签: jenkins xunit.net


    【解决方案1】:

    不,没有用于执行 xUnit.net 测试的 Jenkins 插件。

    最简单的方法是在 Jenkins 作业中运行 Windows 批处理命令。

    您至少可以使用xUnit plugin 来解析来自 xUnit.net 的测试结果 XML 文件,并根据所有测试是否通过来更新构建结果。

    【讨论】:

      【解决方案2】:

      您可以使用 xUnit Jenkins 插件使其工作。

      1) 已安装 xUnit 插件。
      2) 在您的管道中保存一个带有 xUnit 结果的 xml 文件(我使用 https://github.com/Faizan2304/LoggerExtensions 使其与“dotnet test”命令一起使用)。
      3) 使用此代码发布结果:

      step([$class: 'XUnitBuilder',
          thresholds: [[$class: 'FailedThreshold', unstableThreshold: '1']],
          tools: [[$class: 'XUnitDotNetTestType', pattern: '{path to your xml file}']]])
      

      【讨论】:

        【解决方案3】:

        The xUnit Jenkins Plugin now supports xUnit.net:

        1.93 版
        * 添加了对 xUnit.net v2 的支持

        【讨论】:

          【解决方案4】:

          提供的答案真的很有帮助,但我没有设法使用 xUnitPlugin,所以我依靠 ReportUnit 来生成结果。

          1. add NunitXml.TestLogger 打包到测试项目,以便能够将其用作自定义记录器

          2. [Windows 批处理命令] 运行测试并生成“NUnit”样式的输出:

            dotnet test "project.csproj" --no-build --verbosity normal --logger:"nunit;LogFilePath=xunit_results.xml"
            
          3. [Windows 批处理命令] 根据之前的输出生成报告

            "path_to_report_unit\ReportUnit.exe" "path_to_results\xunit_results.xml" "path_to_results\xunit_results.html"
            

          如果需要,可以轻松地将 html 嵌入到某些电子邮件中(例如,可编辑的电子邮件通知 -> 触发器 -> 将附件模式设置为 **\*xunit*.html

          【讨论】:

            【解决方案5】:

            这样的事情会起作用:

            bat'For /R .\Tests\ %%G IN (bin\release\*.test.dll) 做packages\xunit.runner.console.2.4.1\tools\net461\xunit.console.x86。 exe "%%G" -junit "%%~nG.xml"'

            此脚本对“Tests”文件夹中的所有 xunit dll 运行测试。它还将在 junit 中输出测试结果,因此您可以通过以下行简单地发布到 Jenkins

            junit '*.Test.xml'

            【讨论】:

              猜你喜欢
              • 2015-11-20
              • 2021-02-11
              • 2019-11-26
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2018-08-08
              • 1970-01-01
              相关资源
              最近更新 更多