Maven使用JUNIT5和Surefire执行标签的测试

huangapple go评论56阅读模式
英文:

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

org.apache.maven.plugins
maven-surefire-plugin
3.0.0-M5

one

@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.

&lt;plugin&gt;
  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
  &lt;version&gt;3.0.0&lt;/version&gt;
  &lt;configuration&gt;
    &lt;includes&gt;
      &lt;include&gt;ReservationApiIT.java&lt;/include&gt;
    &lt;/includes&gt;
  &lt;/configuration&gt;
&lt;/plugin&gt;

huangapple
  • 本文由 发表于 2023年4月19日 17:40:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76052998.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定