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

查看:549
本文介绍了如何在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文件以便在执行<$时过滤测试命令提示符中的c $ c> 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,看看这个answer 了解详情(包括截图)。

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

此外,您还可以看到使用Maven构建支持在JUnit官方文档中正确配置 maven-surefire-plugin 按标签过滤部分a>对于按标签过滤测试特别有用。

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.


示例(不包括所有带有集成<的测试/ strong>标签



...
<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天全站免登陆