我们的Maven构建在“src / test / java”(名为“* Test.java”)中有很多单元测试,可以从Eclipse和maven构建中正常工作。
我们还在“src / test / java”(名为“* IT.java”)中进行了一系列集成测试,这些测试在Eclipse中运行良好,但我们不会从Maven运行它们,因为测试的性质除手动使用外,使它们不可靠。
我现在写了一个可靠的,我想在CI版本中从mvn命令行执行。到目前为止,我无法弄清楚如何让Failsafe执行它。
我注意到了previous SO post中的建议,并确保我遵循了这些指导原则(我已经使用了正确的位置和命名模式),但是当我运行“failsafe”时,我仍然得到“测试运行:0”:集成测试”。
以下是pom的省略版本:
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
...
</parent>
<artifactId>usl-features-install</artifactId>
<name>usl-features-install</name>
<url>http://maven.apache.org</url>
<packaging>bundle</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
...
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
当我运行“mvn failsafe:integration-test”时,我看到以下内容:
[INFO] ------------------------------------------------------------------------
[INFO] Building usl-features-install 3.1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-failsafe-plugin:2.20.1:integration-test (default-cli) @ usl-features-install ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
更新:
参考提供的答案,我最初添加了以下执行块(和版本):
<version>2.20.1</version>
<executions>
<execution>
<goals>
<!-- <goal>verify</goal> -->
<goal>integration-test</goal>
</goals>
</execution>
</executions>
然后运行“mvn failsafe:integration-test”。这没有效果。
然后我删除了上面“验证”的评论包装并运行“mvn verify”。结果非常令人困惑。运行“failsafe:integration-test”和以前一样,但是运行“mvn verify”会做到以下几点:
[INFO] --- maven-failsafe-plugin:2.20.1:integration-test (default) @ usl-features-install ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-failsafe-plugin:2.20.1:verify (default) @ usl-features-install ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.968 s
[INFO] Finished at: 2017-10-25T10:41:26-07:00
[INFO] Final Memory: 35M/498M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.20.1:verify (default) on project usl-features-install: There are test failures.
[ERROR]
[ERROR] Please refer to C:\users\<myuid>\git\oce_usl\usl-parent\usl-features-install\target\failsafe-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
请注意,它会两次报告故障安全。第一次仍然无所事事,第二次失败。
提到的“转储文件”具有以下堆栈跟踪,使问题更加混乱:
java.lang.NoSuchMethodError: org.apache.maven.surefire.report.RunListener.testSetStarting(Lorg/apache/maven/surefire/report/ReportEntry;)V
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:235)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:161)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:373)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:334)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:119)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:407)
更新:
我尝试用“-X”运行mvn。它当然产生了很多输出,但这是它在尝试运行测试时显示的内容:
[DEBUG] Forking command line: cmd.exe /X /C ""C:\Program Files\Java\jdk1.8.0_102\jre\bin\java" -javaagent:C:\\Users\\<myuid>\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.7.8\\org.jacoco.agent-0.7.8-runtime.jar=destfile=C:\\users\\<myuid>\\git\\oce_usl\\usl-parent\\usl-features-install\\target\\jacoco.exec -jar C:\cygwin64\tmp\surefire29734070406705707\surefirebooter6462732870353032119.jar C:\cygwin64\tmp\surefire29734070406705707 2017-10-25T15-17-49_742-jvmRun1 surefire1801590010194716332tmp surefire_05587249170077752672tmp"
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-failsafe-plugin:2.20.1:verify (default) @ usl-features-install ---
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-failsafe-plugin:2.20.1:verify from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-failsafe-plugin:2.20.1, parent: sun.misc.Launcher$AppClassLoader@5c647e05]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-failsafe-plugin:2.20.1:verify' with basic configurator -->
[DEBUG] (s) basedir = C:\users\<myuid>\git\oce_usl\usl-parent\usl-features-install
[DEBUG] (s) reportsDirectory = C:\users\<myuid>\git\oce_usl\usl-parent\usl-features-install\target\surefire-reports
[DEBUG] (s) skip = false
[DEBUG] (f) summaryFile = C:\users\<myuid>\git\oce_usl\usl-parent\usl-features-install\target\failsafe-reports\failsafe-summary.xml
[DEBUG] (s) testClassesDirectory = C:\users\<myuid>\git\oce_usl\usl-parent\usl-features-install\target\test-classes
[DEBUG] (s) testFailureIgnore = false
[DEBUG] (f) session = org.apache.maven.execution.MavenSession@6bf13698
[DEBUG] -- end configuration --
[DEBUG] Failsafe report directory: C:\users\<myuid>\git\oce_usl\usl-parent\usl-features-install\target\surefire-reports
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
这表明它正在使用运行单元测试所需的jacoco代理。我不需要它进行集成测试。我不确定如何关闭它,或者这是否是一个因素。
更新:
我认为我已经达成了“修复”,或者至少是中期解决方案。
我觉得“NoSuchMethodError”问题可能是关键所在,因此我搜索了类似事件,并发现了以下问题:https://github.com/junit-team/junit5/issues/809。
所以,我所做的是将我的故障安全版本从2.20.1更改为2.19.1(这显然会导致使用相同版本的surefire),现在它不会以这种方式失败。
然而,我现在看到另一个偶然出现的问题,“命令NOOP意外地读取长度为4的Void数据。”http://maven.40175.n5.nabble.com/surefire-forked-vm-failed-td5858900.html),这似乎产生了一个建议,甚至进一步退回到surefire 2.18。 1。
这与此测试是PaxExam测试的事实相结合,该测试呈现其他并发症和混乱。我想我的结论是修复比问题更糟糕。
答案 0 :(得分:1)
您是否尝试通过mvn clean verify
在命令行上运行,还有maven-failsafe-plugin生命周期,如文档中所述,通过执行?
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>