当 testng 测试失败时 mvn build 失败
mvn build fail when testng test fail
我有 2 个不同的测试
public class testcase1 {
@Test
public void testcase1() {
System.out.println("test1 ");
}
@Test
public void testcase2() {
System.out.println("test 2 ");
}
@Test
public void testcase3() {
Assert.assertTrue(false);
}
}
当我在终端中使用 mvn clean test
时,它执行所有测试用例并且我 git 报告但它标记为构建失败
这是日志
[ERROR] Tests run: 3, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 7.588 s <<< FAILURE! - in TestSuite
[ERROR] fail1.testcase2.testcase2 Time elapsed: 0.012 s <<< FAILURE!
java.lang.AssertionError: did not expect to find [true] but found [false]
at fail1.testcase2.testcase2(testcase2.java:10)
[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] testcase2.testcase2:10 did not expect to find [true] but found [false]
[INFO]
[ERROR] Tests run: 3, Failures: 1, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 59.248 s
[INFO] Finished at: 2019-12-02T07:30:00+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test (default-test) on project neeewdev1: There are test failures.
[ERROR]
[ERROR] Please refer to /home/neeewdev1/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
请您解释一下为什么当 testng 结果失败时构建也失败?我该如何解决这个问题?
您正在尝试测试应用程序而不是构建它。无论如何,如果你真的想构建它并跳过测试,你应该 运行
mvn clean install -DskipTest
Surefire 插件在构建生命周期的测试阶段用于执行应用程序的单元测试
要么你可以跳过测试,要么即使测试失败你仍然想构建项目那么你可以在 pom.xml
中使用 **<testFailureIgnore>true</testFailureIgnore>**
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
我有 2 个不同的测试
public class testcase1 {
@Test
public void testcase1() {
System.out.println("test1 ");
}
@Test
public void testcase2() {
System.out.println("test 2 ");
}
@Test
public void testcase3() {
Assert.assertTrue(false);
}
}
当我在终端中使用 mvn clean test
时,它执行所有测试用例并且我 git 报告但它标记为构建失败
这是日志
[ERROR] Tests run: 3, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 7.588 s <<< FAILURE! - in TestSuite
[ERROR] fail1.testcase2.testcase2 Time elapsed: 0.012 s <<< FAILURE!
java.lang.AssertionError: did not expect to find [true] but found [false]
at fail1.testcase2.testcase2(testcase2.java:10)
[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] testcase2.testcase2:10 did not expect to find [true] but found [false]
[INFO]
[ERROR] Tests run: 3, Failures: 1, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 59.248 s
[INFO] Finished at: 2019-12-02T07:30:00+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test (default-test) on project neeewdev1: There are test failures.
[ERROR]
[ERROR] Please refer to /home/neeewdev1/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
请您解释一下为什么当 testng 结果失败时构建也失败?我该如何解决这个问题?
您正在尝试测试应用程序而不是构建它。无论如何,如果你真的想构建它并跳过测试,你应该 运行
mvn clean install -DskipTest
Surefire 插件在构建生命周期的测试阶段用于执行应用程序的单元测试
要么你可以跳过测试,要么即使测试失败你仍然想构建项目那么你可以在 pom.xml
中使用**<testFailureIgnore>true</testFailureIgnore>**
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>