我已经设置了Maven来触发一些junit5测试。
当我跑步时:
mvn clean integration-test
我看到了项目构建,然后它也运行测试。我发现其中一项单元测试失败。
在控制台输出中,我进一步看到:
[INFO] BUILD SUCCESS
我在做什么错?我的期望是,失败的测试运行将停止maven之类的工具并返回退出代码1。
这在CI中尤其令人沮丧,因为它看起来很健康,因为退出代码返回零。
编辑:这是POM XML:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.(removedforstackoverflowpost)</groupId>
<artifactId>(removedforstackoverflowpost)</artifactId>
<packaging>jar</packaging>
<version>0.0.1</version>
<name>(removedforstackoverflowpost)</name>
<url>(removedforstackoverflowpost)</url>
<description>(removedforstackoverflowpost)</description>
<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
</license>
</licenses>
<developers>
<developer>
<name>(removedforstackoverflowpost)</name>
<email>(removedforstackoverflowpost)</email>
<organization>(removedforstackoverflowpost)</organization>
<organizationUrl>(removedforstackoverflowpost)</organizationUrl>
</developer>
</developers>
<scm>
<connection>(removedforstackoverflowpost)</connection>
<developerConnection>(removedforstackoverflowpost)</developerConnection>
<url>(removedforstackoverflowpost)</url>
</scm>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-console-standalone</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<!-- latest version (2.20.1) does not work well with JUnit5 -->
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.3</version>
</dependency>
</dependencies>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<properties>
<configurationParameters>
junit.jupiter.extensions.autodetection.enabled = true
</configurationParameters>
</properties>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<argLine>
--illegal-access=permit
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>
我正在运行Java 11
当我输入此测试命令时:
mvn -ff clean integration-test
我得到的输出像这样结束:
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec - in com.github.(removedforstackoverflowpost)
Results :
Failed tests:
SomeTest.testSomething1:13 expected: <1> but was: <2>
Tests run: 4, Failures: 1, Errors: 0, Skipped: 0
[ERROR] There are test failures.
Please refer to (removedforstackoverflowpost)/target/surefire-reports for the individual test results.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ (removedforstackoverflowpost) ---
[INFO] Building jar: (removedforstackoverflowpost)....-0.0.1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.360 s
[INFO] Finished at: 2018-12-12T00:45:03-08:00
[INFO] ------------------------------------------------------------------------
我是一个初学者,所以我问一个过于简单的问题表示歉意。我是Java / Maven / JUnit5的新手,但我只是在寻找使测试引起非零退出代码的方法。这样,当测试失败时,我的CI运行(我碰巧使用CircleCI,但这没关系)将显示为失败。
我在Mac上工作,在此故障单上描述的不良行为在本地Mac工作站以及CircleCI上都以相同的方式发生。
答案 0 :(得分:0)
pom.xml的第102行指示Maven忽略故障。只需删除<testFailureIgnore>true</testFailureIgnore>
,构建就会失败。