You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TeamCity重复显示测试结果:默认Surefire报告与JUnit XML报告

解决TeamCity同时显示JUnit与Surefire测试报告的问题

方法1:通过Maven配置禁用Surefire的XML报告生成

TeamCity默认会自动识别Surefire插件生成的target/surefire-reports下的XML报告,最直接的方式是让Maven不生成Surefire的默认XML报告,只保留自定义的JUnit报告。在项目的pom.xml中修改Surefire插件配置:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>你的Surefire版本号</version>
            <configuration>
                <!-- 禁用Surefire默认的XML报告生成 -->
                <disableXmlReport>true</disableXmlReport>
                <!-- 如需保留控制台输出,可添加此配置 -->
                <useFile>false</useFile>
            </configuration>
        </plugin>
    </plugins>
</build>

配置后Surefire不再生成默认XML报告,TeamCity也就不会识别到这部分测试结果。

方法2:在TeamCity中配置忽略Surefire报告路径

若不想修改Maven配置,可在TeamCity构建配置中设置忽略特定报告路径:

  • 进入目标构建配置,找到构建功能里的「JUnit XML报告处理」
  • 在「报告路径」中,先填写自定义JUnit报告的路径(如**/custom-junit-reports/*.xml),再添加排除规则:在路径前加!,即!**/surefire-reports/*.xml
  • 最终报告路径配置示例:**/custom-junit-reports/*.xml,!**/surefire-reports/*.xml

方法3:修改TeamCity的Maven构建步骤参数

在TeamCity的Maven构建步骤中,通过命令行参数强制禁用Surefire报告:

  • 找到构建步骤的「命令行参数」输入框
  • 添加参数:-Dsurefire.disableXmlReport=true
  • 此方式和修改pom.xml的效果一致,无需改动项目配置

注意事项

  • 确保自定义JUnit报告的路径在TeamCity的JUnit XML报告处理中配置正确,路径需能匹配到实际生成的报告文件
  • 若之前有过构建记录,建议在构建步骤中添加clean命令清理target目录,避免旧的Surefire报告被TeamCity识别

内容的提问来源于stack exchange,提问作者uzair majid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 12:50:50