解决mvn clean install遇到testng单元测试失败时打包也失败的问题

解决mvn clean install遇到testng单元测试失败时打包也失败的问题

看这个之前请先看这个
Jenkins执行Testng

比如我现在就有一个单元测试失败的项目

执行mvn clean install的时候就会报错

下面是我现在的pom.xml

但我们不希望这样,怎么办

xml 复制代码
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M4</version>
                <configuration>
<!--                    这个testFailureIgnore就是就算执行失败也可以正常打包的关键-->
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>

新增上面这个配置,即可

再次执行mvn clean install,就算失败了也没问题,照样打包成功

如果要集成jenkins,再加上suiteXmlFiles这个配置

xml 复制代码
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M4</version>
                <configuration>
<!--                    这个testFailureIgnore就是就算执行失败也可以正常打包的关键-->
                    <testFailureIgnore>true</testFailureIgnore>
                    <argLine>-Dfile.encoding=UTF-8</argLine>
                    <suiteXmlFiles>
                        <!--suppress UnresolvedMavenProperty -->
                        <suiteXmlFile>${xmlFileName}</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>

我们接下来大致讲讲这个surefire

maven-surefire-plugin插件默认会自动执行测试源码包(即test目录下)中遵循以下命名规则的java测试类。

*/Test .java

**/*Test.java

**/*TestCase.java

在Maven构建过程中,测试是其生命周期的一部分,每一个构建过程都会执行项目中的测试用例,如果遇到一个测试失败,默认会停止当前的构建。

如果遇到测试失败时,依然希望继续构建项目,那么需要设置surefire插件的testFailureIgnore属性为true。

相关推荐
howard200521 小时前
1.4 单元测试与热部署
spring boot·单元测试·热部署
獨枭2 天前
在 IntelliJ IDEA 中使用 JUnit 进行单元测试
junit·单元测试·intellij-idea
不爱学英文的码字机器2 天前
用Python实现自动化测试:从单元测试到API验证
python·测试工具·单元测试
獨枭3 天前
在 CLion 中使用 Google Test 进行单元测试
c++·单元测试
四角小裤儿儿3 天前
软件测试(三)——Bug篇
功能测试·面试·单元测试·bug
WIN赢3 天前
Spring编写单元测试的工具介绍:JUnit、Mockito、AssertJ
spring·junit·单元测试
獨枭3 天前
在 macOS 上使用 CLion 进行 Google Test 单元测试
macos·单元测试·策略模式
阿古达木3 天前
我在团队内部提倡禁用单元测试
前端·单元测试
hillstream34 天前
单元测试与仿真程序之间的选择
单元测试
程序员的世界你不懂4 天前
页面对象实现自动化测试,playwright框架
python·测试工具·microsoft·单元测试