How to use JUnit 5 @Tag with IntelliJ and Maven

≡放荡痞女 提交于 2019-11-27 08:34:36

问题


I would like to use the @Tag available in JUnit 5 in order to easily filter my tests.

I have found in this blog input from September 2016 that IntelliJ was not supporting @Tag. Not sure what the current status is though.

Also, I am very new to using Maven but I have tried modifying the POM file in order to filter tests when executing mvn test in a command prompt. No luck.


回答1:


Here's the solution I found: changing the JUnit versions in the POM file from ...

<junit.jupiter.version>5.0.0-M2</junit.jupiter.version>
<junit.vintage.version>4.12.0-M2</junit.vintage.version>
<junit.platform.version>1.0.0-M2</junit.platform.version>

to

<junit.jupiter.version>5.0.0-M3</junit.jupiter.version>
<junit.vintage.version>4.12.0-M3</junit.vintage.version>
<junit.platform.version>1.0.0-M3</junit.platform.version>

allowed Maven to recognize the @Tag.




回答2:


Now it is possible with Intellij IDEA 2018.1, take a look at this answer for details (including screenshot).


Also, you can see Build Support with Maven in JUnit official documentation for a proper configuration of maven-surefire-plugin. The section Filtering by Tags can be especially useful to filter tests by tags.

Example (excluding all tests with the "integration" tag):

...
<build>
    <plugins>
        ...
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.21.0</version>
            <configuration>
                <properties>
                    <excludeTags>integration</excludeTags>
                </properties>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider</artifactId>
                    <version>1.2.0</version>
                </dependency>
                ...
            </dependencies>
        </plugin>
    </plugins>
</build>
...


来源:https://stackoverflow.com/questions/42808861/how-to-use-junit-5-tag-with-intellij-and-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!