dan*_*y-v 33 java maven maven-failsafe-plugin
我已经梳理了StackOverflow和许多其他网站,发现了许多其他相关的帖子,并且已经遵循了所有的建议,但最终,故障安全正在跳过我的测试.
我的JUnit测试位于:
myModule/src/main/test/java/ClientAccessIT.java
我正在跳过surefire,因为这个模块中没有单元测试:
<!-- POM snippet -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用failsafe运行集成测试:
<!-- POM snippet -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>run-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但是,当我跑步时,mvn verify我看到了这个:
[INFO] --- maven-failsafe-plugin:2.14.1:integration-test (run-tests) @ rest-services-test ---
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
Run Code Online (Sandbox Code Playgroud)
我花了最后4个半小时的冲刷,任何帮助将不胜感激.唯一可能值得一提的是我有Cargo设置并拆除Tomcat容器.有没有人看到明显的问题?
Kep*_*pil 19
您需要重命名您的测试类.
你可以在文档中找到插件默认查找的名称,如@acdcjunior所指出:
默认情况下,Failsafe插件将自动包含具有以下通配符模式的所有测试类:
- "
**/IT*.java" - 包括其所有子目录和所有以"IT"开头的java文件名.- "
**/*IT.java" - 包括其所有子目录和以"IT"结尾的所有java文件名.- "
**/*ITCase.java" - 包括其所有子目录和所有以"ITCase"结尾的java文件名.
小智 13
您的测试不在默认测试源目录src/test/java中.看到:
https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
Mymodule中/ SRC /主/测试/ JAVA/ClientAccessIT.java
应该:
Mymodule中/ SRC /测试/ JAVA/ClientAccessIT.java
您还可以更新您的pom文件(如果您真的希望测试生活在main中),以包括:
<build>
<testSources>
<testSource>
<directory>src/main/test</directory>
</testSource>
</testSources>
</build>
Run Code Online (Sandbox Code Playgroud)
bar*_*yku 12
对于多模块项目,子项目需要按照以下方式声明插件,
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
Run Code Online (Sandbox Code Playgroud)
版本继承自父pom.如果没有上面定义的,单独使用父pom中的插件将无效.
I was having the same issue and tried a few of the suggested options here. I am developing a Spring Boot application using JUnit 5. Unfortunately, none of my integration tests (located in src/test/java and suffixed with *TestIT.java) were getting picked up, regardless of the advertising of the plugin to do so. I tried downgrading to 2.18.1, 2.19.1 and tried both removing the <executions> and <configuration> sections to attempt to use even the plugin's default functionality, but no luck.
I finally changed the version to the latest (as of the time of writing) to 2.22.0, and viola. Here is the configuration I added to the <build><plugins> section of my pom. And even better, I don't need to add executions that define the integration-test and verify goals that you see most people include; failsafe executes these by default. I've included my surefire plugin configuration as well, since I am using it to execute unit tests during the test phase of the maven lifecycle.
Edit: I also had to ad the integration-test and verify executions to the plugin configuration as well.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version><!--$NO-MVN-MAN-VER$-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version><!--$NO-MVN-MAN-VER$ -->
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
And just for good measure, to tell surefire and failsafe to use JUnit 5, I am including this in my <dependencies> section:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
Eclipse displays a warning (yellow squiggly underline) under the version tag, hence the inclusion of the <!--$NO-MVN-MAN-VER$ --> error. I'm sure there's a better way to deal with this, but it works for me in this case.
To speed up testing this configuration, and to avoid having to go through all of the earlier lifecycle phases before test, integration-test orverify phases, I used the following commands to quickly validate:
mvn failsafe:integration-test (runs only integration tests)mvn surefire:test (runs only unit tests)Hope this helps someone. Cheers!
我也有类似的问题,但需要包装元素是"pom".确保正在编译测试源文件并使用maven-compiler-plugin将其添加到.../target/test-classes文件夹:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
如果您碰巧使用Spring Boot 2.4或更高版本,并且您的测试仍然使用JUnit 4,请记住放置此依赖项:
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
2.4 版spring-boot-starter-test仅包含 JUnit 5,并删除了为运行基于 JUnit 3 和 4 的测试提供 TestEngine 的老式引擎。
如果没有那个老式引擎,所有 JUnit 4 测试都会被默默忽略。
| 归档时间: |
|
| 查看次数: |
17822 次 |
| 最近记录: |