gpt4 book ai didi

java - Eclipse 执行集成测试,但 Maven 不执行

转载 作者:行者123 更新时间:2023-12-02 12:05:22 24 4
gpt4 key购买 nike

我们的 Maven 构建在“src/test/java”(名为“*Test.java”)中有很多单元测试,这些测试在 Eclipse 和 Maven 构建中运行良好。

我们在“src/test/java”(名为“*IT.java”)中还有一堆集成测试,它们在 Eclipse 中运行良好,但我们不会从 Maven 运行它们,因为测试的性质使它们不可靠,除非手动使用。

我现在已经编写了一个可靠的代码,我想在 CI 构建中从 mvn 命令行执行它。到目前为止,我还不知道如何让 Failsafe 执行它。

我注意到 previous SO post 中的建议并确保我遵循了这些准则(我已经使用了正确的位置和命名模式),但当我运行“failsafe:integration-test”时,我仍然得到“测试运行: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 failuresafe: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] ------------------------------------------------------------------------

更新:

引用提供的答案,我最初添加了以下执行 block (和版本):

            <version>2.20.1</version>
<executions>
<execution>
<goals>
<!-- <goal>verify</goal> -->
<goal>integration-test</goal>
</goals>
</execution>
</executions>

然后运行“mvn failuresafe:integration-test”。这没有效果。

然后,我删除了上面“verify”的注释包装并运行“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。它当然生成了大量输出,但以下是它在尝试运行 it 测试时显示的内容:

[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),现在它不会以这种方式失败。

但是,我现在偶尔会遇到另一个问题:“Command NOOP 意外读取长度为 4 的 Void 数据。”( http://maven.40175.n5.nabble.com/surefire-forked-vm-failed-td5858900.html ),这似乎会产生进一步退缩的建议,以确保 2.18.1。

事实是,该测试是 PaxExam 测试,会带来其他复杂性和困惑。我想我得出的结论是解决方案比问题本身更糟糕。

最佳答案

您是否尝试通过mvn clean verify在命令行上运行此外您是否绑定(bind)了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>

关于java - Eclipse 执行集成测试,但 Maven 不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46937754/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com