如何在 IntelliJ 和 Maven 中使用 JUnit 5 @Tag [英] How to use JUnit 5 @Tag with IntelliJ and Maven

查看:36
本文介绍了如何在 IntelliJ 和 Maven 中使用 JUnit 5 @Tag的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 JUnit 5 中可用的 @Tag 来轻松过滤我的测试.

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

我在这个博客中找到了 2016 年 9 月输入的 IntelliJ 不支持 @Tag.不确定目前的状态.

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

另外,我对使用 Maven 非常陌生,但我尝试修改 POM 文件,以便在命令提示符下执行 mvn test 时过滤测试.没有运气.

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.

推荐答案

现在可以使用 Intellij IDEA 2018.1,看看这个 回答了解详情(包括截图).

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

此外,您可以看到 Build Support withJUnit 官方文档中的 Maven 用于正确配置 maven-surefire-plugin.按标签过滤 对于按标签过滤测试特别有用.

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.

示例(不包括所有带有integration"标签的测试):

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

这篇关于如何在 IntelliJ 和 Maven 中使用 JUnit 5 @Tag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆