英文:
Maven Test Execution by Tags with JUNIT5 and Surefire
问题
I have test and tagged the tests by the @Tag annotation from the org.junit.jupiter.api package.
This is the pom.xml
@Tag("one")
public class BubblegumApiIT {
// SOME TEST CODE
}
Now I want to execute just the tests that are tagged by "one". When I configure the JUNIT with Intellj (instead of 'CLASS' I use 'TAGS') it works. However, the equivalent mvn command does not work.
The equivalent maven command would be mvn -Dgroups=one test or?
But I am executing exactly 0 tests then.
Anybody had this issue before?
英文:
I have test and tagged the tests by the @Tag annotation from the org.junit.jupiter.api package.
This is the pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<groups>one</groups>
</configuration>
</plugin>
</plugins>
</build>
@Tag("one")
public class BubblegumApiIT {
// SOME TEST CODE
}
Now I want to execute just the tests that are tagged by "one". When I configure the JUNIT with Intellj (instead of 'CLASS' I use 'TAGS') it works.
However, the equivalent mvn command does not work.
The equivalent maven command would be mvn -Dgroups=one test or?
But I am executing exactly 0 tests then.
Anybody had this issue before?
答案1
得分: 0
默认情况下,Surefire 插件会自动包含所有符合以下通配符模式的测试类:
- "**/Test*.java" - 包括所有子目录以及所有以"Test"开头的Java文件名。
- "**/*Test.java" - 包括所有子目录以及所有以"Test"结尾的Java文件名。
- "**/*Tests.java" - 包括所有子目录以及所有以"Tests"结尾的Java文件名。
- "**/*TestCase.java" - 包括所有子目录以及所有以"TestCase"结尾的Java文件名。
您的测试类不符合默认的通配符模式。要么将其重命名,要么在插件配置中指定。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<includes>
<include>ReservationApiIT.java</include>
</includes>
</configuration>
</plugin>
英文:
By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:
- "**/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test".
- "**/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test".
- "**/*Tests.java" - includes all of its subdirectories and all Java filenames that end with "Tests".
- "**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase".
Your test class do not follow the default wildcard patterns. Either rename it or specify in the plugin configuration.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<includes>
<include>ReservationApiIT.java</include>
</includes>
</configuration>
</plugin>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论