Jenkins 不从文件输出 Junit 报告信息

2024-01-08

Problem

Jenkins 未选取 junit 格式的报告,导致报告未在项目的状态屏幕中列出。

Details

junit 格式的报告数据由名为 Karma-runner(以前称为 Testaulous)的测试框架生成。被忽略的文件创建于/target/surefire-reports-- 与创建 Surefire 生成的报告的位置相同。报告数据看起来与 Maven Surefire 插件生成的数据几乎相同,只是它的父元素是<testsuites>代替<testsuite> -- <testsuite>是肯定生成的报告作为报告文件的父元素的内容。以下是 karma 生成的 junit 格式报告中的一个片段,名为TEST-karma.resultsTest.xml:

Junit 格式的 Karma 生成的报告文件,TEST-karma.resultsTest.xml

<?xml version="1.0"?>
<testsuites>
  <testsuite name="PhantomJS 1.9 (Mac)" package="karma.tests" timestamp="2013-04-10T13:32:26" id="0" hostname="jgmbp.local" tests="16" errors="0" failures="0" time="0.069">
    <properties>
      <property name="browser.fullName" value="Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.0 Safari/534.34"/>
    </properties>
    <testcase name="successfully cancels a new member" time="0.006" classname="karma.tests PhantomJS 1.9 (Mac).Household Controller"/>
    <testcase name="should parse an existing re-eval create date, setting the data in scope" time="0.003" classname="karma.tests PhantomJS 1.9 (Mac).Re-Eval Controller"/>
    <system-out><![CDATA[
]]></system-out>
    <system-err/>
  </testsuite>
</testsuites>

Karma 测试在我的 Maven 构建的测试阶段运行。我尝试创建仅生成这一 junit-report 文件的项目并运行构建,以便所有 junit 测试和 karma 测试生成报告文件。詹金斯总是会接受万无一失的测试,但永远不会接受业力测试。

感谢您的任何意见!


您可以在 Jenkins 中发布 Karma 测试结果即使在构建 Maven 项目时,如果你用一些小技巧来愚弄詹金斯:在运行 Karma 测试的 Javascript 模块中运行 Surefire 插件.

Surefire 插件不会在您的 Javascript 模块中找到任何 JUnit 测试,但它会通知 Jenkins Surefire 测试结果可用。

下面是一个示例 pom.xml 和来自 Gruntfile.js 的片段,它运行 Karma 测试和 JSHint 代码分析,并使 Jenkins 发布测试结果和代码分析结果。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.xxx.yyyy</groupId>
<artifactId>zzzzz</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Zzzzz</name>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <phase>generate-resources</phase>
                    <configuration>
                        <target>
                            <exec
                                dir="${basedir}"
                                executable="npm"
                                failonerror="true">
                                <arg value="install"/>
                            </exec>
                            <exec
                                dir="${basedir}"
                                executable="bower"
                                failonerror="true">
                                <arg value="install"/>
                            </exec>
                            <exec
                                    dir="${basedir}"
                                    executable="grunt"
                                    failonerror="true">
                                <arg value="--no-color"/>
                                <arg value="build"/>
                            </exec>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>

                <execution>
                    <id>jshint</id>
                    <phase>test</phase>
                    <configuration>
                        <target>
                            <exec
                                dir="${basedir}"
                                executable="grunt"
                                failonerror="false">
                                <arg value="--no-color"/>
                                <arg value="karma:run"/>
                            </exec>
                            <exec
                                dir="${basedir}"
                                executable="grunt"
                                failonerror="false">
                                <arg value="--no-color"/>
                                <arg value="jshint:jenkins"/>
                            </exec>
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>

            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12.4</version>
            <executions>
                <!-- This is a hack to get Jenkins to publish Karma test results when running a Maven project: we run 0 surefire tests, so Jenkins publishes the report of the Karma tests. -->
                <execution>
                    <id>dummySureFire</id>
                    <phase>test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>2.12</version>
            <executions>
                <!-- This is a hack to get Jenkins to publish JSHint results when running a Maven project: we run checkstyle, so Jenkins publishes the report of the JSHint run. -->
                <execution>
                    <id>dummyCheckStyle</id>
                    <phase>test</phase>
                    <goals>
                        <goal>checkstyle</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<reporting>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <version>2.12.4</version>
        </plugin>
    </plugins>
</reporting>
</project>

在 Gruntfile.js 中,我们有以下内容。输出文件名必须以 TEST- 开头才能发布:

karma: {
        run: { // produces reports for Jenkins
            configFile: 'karma.conf.js',
            singleRun: true,
            reporters : ['junit', 'coverage'],
            junitReporter : {
                outputFile: 'target/surefire-reports/TEST-results.xml'
            },
        ...

对于 Gruntfile.js 中的 JSHint:

jshint: {
        all: [
            'Gruntfile.js',
            '<%= yeoman.app %>/scripts/{,*/}*.js'
        ],
        options: {
            jshintrc: '.jshintrc',
            reporter: require('jshint-stylish')
        },
        jenkins: {
            options: {
                reporter: 'checkstyle',
                reporterOutput: "target/checkstyle-result.xml"
            },
            src: [
                'Gruntfile.js',
                '<%= yeoman.app %>/scripts/{,*/}*.js'
            ]
        }
    }

在 Jenkins 作业配置中,您只需选中“构建设置”部分中的“发布 Checkstyle 分析结果”框,即可让 Jenkins 发布 JSHint 结果。发布测试结果不需要额外的 Jenkins 作业配置。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Jenkins 不从文件输出 Junit 报告信息 的相关文章

随机推荐

  • Text[] 数组列的表索引

    我有一个 PostgreSQL 数据库表text 数组 在其上定义的列 我使用这些列以这种方式搜索数据库中的特定记录 select obj from business where street ANY address line 1 and
  • ExtJs。设置行编辑单元格值

    我有带有 RowEditing 插件的网格 编辑器有 2 列 一列带有组合框 另一列带有禁用的文本字段 我需要在更改组合框值后更改文本字段值 我有组合框监听器 listeners select function combo records
  • 在 AWS CDK 中组织安全组规则的最佳方式

    对于我的示例 我有一个 EKS 集群 RDS 数据库和一个 VPN 客户端端点 每个端点都有自己的安全组 我希望在这些安全组之间显式定义出口 入口规则 我在RDS堆栈中定义数据库安全组 导入EKS VPNaws ec2 SecurityGr
  • SQL Server:根据参数将存储过程结果插入表中

    我有一个存储过程Test Sp它以这种方式返回数据 Id Name Age Address State Country 1 ManiS 25 aaaa bbb ccc 该存储过程返回 6 列数据 但我只想将前 2 列插入临时表中 我的临时表
  • Bootstrap 3 DatePicker - 如何在不重置选择器配置的情况下重置所选日期?

    我正在尝试重置单击按钮时选定的日期 但到目前为止我只能清除input元素 选择器上没有实际日期 下面的代码重置了所有内容 包括配置和日期 所以它显然不是我需要的 datepicker datepicker update resets eve
  • 如何从曲线拟合中提取残差

    我在 Matlab R2016a 中使用曲线拟合来找到两个数组之间的最佳拟合 一个数组表示给定纬度和经度处的某个值 另一个数组表示收集该值的日期 在使用曲线拟合工具时 我能够找到一条最佳拟合线并绘制残差 我只关心残差 但是 当我将残差导出到
  • PayPal IPN 使用 PHP 生成 HTTP 302 错误

    我有一个可以运行的 IPN 脚本 并且已经工作了一段时间 最近我开始得到一个HTTP 1 1 302 Moved Temporarily作为回应 无法确定原因 以下是与发布到 PayPal 并获取响应相关的代码 sd fsockopen s
  • 使用 SQL 查询的逗号分隔值

    我的 SQL 表如下 City Code Post Code Post Code Description 100 A1 ABC 100 C8 XYZ 100 Z3 MNO 200 D4 LMN 300 E3 IJK 300 B9 RST 它
  • 在C++中,主函数是程序的入口点,我如何将其更改为其他函数?

    有人问我一个面试问题 将 C 或 C 程序的入口点从main 任何其他功能 这怎么可能 在标准 C 中 我相信 C 也是如此 您不能 至少对于托管环境不能 但见下文 该标准规定 C 代码的起点是main 标准 c99 没有留下太多争论的余地
  • 在sql查询中传递node.js参数

    我有一些从客户端接收的日期字段 基本上 我想在我的 SQL 数据库中搜索这个日期 我应该如何在查询中传递年 月和日期 我只想用从客户端收到的新日期替换该日期 如何使用 mssql 驱动程序实现此目的 https www npmjs com
  • 在 grails/hibernate 中使用 uuid 或 guid 作为 id

    我需要将 GUID UUID 作为行的 id 列 这是为了能够在线和离线创建条目 当然合并时不会在PK上产生这些冲突 我知道我可以减轻这个问题 但我想保持简单 并且有遗留应用程序已经使用 uuid guid 来定义关系 稍后还需要双向同步数
  • Oracle JDK 和 OpenJDK 之间的区别

    注意 这个问题来自 2014 年 从 Java 11 OpenJDK 和 Oracle 开始 JDK 正在趋同 Oracle 和 OpenJDK 之间有什么重要区别吗 例如 垃圾收集和其他 JVM 参数是否相同 两者之间的 GC 工作方式是
  • 变量周围的大括号

    我正在尝试理解这段代码 我什至不知道它的语法是否正确 我猜是练习的一部分 records 大括号表示什么 我见过同样的情况 但有一个 使用运算符代替 如果这有影响的话 多谢你们 The perlref 文档的 使用引用 部分 http pe
  • 等待递归线程生产者

    我有一个收集器 用于搜索游戏中的动作 我以递归搜索的方式进行搜索 以获取游戏中每一个可能的动作 出于性能原因 我使用线程池 每个找到的移动都会向池中添加一个新线程 以扩展旧的移动 这是一些代码 protected static List
  • em 是如何计算的?

    我注意到你可以使用 1em 并且它在不同的网站上看起来会有所不同 em 与什么成比例 使用的字体 最大的字体大小 页面宽度 高度 See http w3schools com cssref css units asp http w3scho
  • 更改 R 类包 android/eclipse

    我正在android中的一个小界面上工作 当我运行它时 出现 xxx应用程序已意外停止 我正在寻找可能的错误 但什么也没找到 无论如何 我想更改R类包名称 当我重构 gt 重命名它时 eclipse会在旧包中生成另一个包 即使我删除该包ec
  • 为什么我们应该在 PHP 中使用静态调用?

    为什么我们要在 PHP5 中使用静态变量或静态调用静态方法 也许是为了提高性能 我们使用静态类变量在类的所有实例之间共享数据 并且我们使用静态方法 最好是private static 来计算类功能所需的东西 但独立于类实例状态 this 性
  • 使用 cmake 将 clr 支持设置为 true

    我正在尝试使用 cmake 生成托管 C 代码 下面是我添加的脚本 SET TARGET PROPERTIES PROJECT NAME PROPERTIES COMPILE FLAGS clr STRING REPLACE EHsc EH
  • 如何将 SQL 连接字符串与 ADO.NET 实体数据模型结合使用

    我正在尝试以一种可以即时更改我指向的数据库的方式使用 ADO NET 实体数据模型 更改数据库可能需要全新的连接字符串 有些数据库位于不同的服务器上 因此 我需要能够向 ADO NET 实体数据模型传递自定义连接字符串 格式如下 serve
  • Jenkins 不从文件输出 Junit 报告信息

    Problem Jenkins 未选取 junit 格式的报告 导致报告未在项目的状态屏幕中列出 Details junit 格式的报告数据由名为 Karma runner 以前称为 Testaulous 的测试框架生成 被忽略的文件创建于