如何选择要使用Maven执行的JUnit5标签

如何选择要使用Maven执行的JUnit5标签

本文介绍了如何选择要使用Maven执行的JUnit5标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚升级了解决方案以使用JUnit5.现在尝试为我的测试创建具有两个标签的标签:@Fast@Slow.首先,我使用下面的maven条目来配置要使用默认版本运行的测试.这意味着当我执行mvn test时,只会执行我的快速测试.我假设我可以使用命令行来覆盖它.但是我不知道要输入什么来运行我的慢速测试....

I have just upgraded my solution to use JUnit5. Now trying to create tags for my tests that have two tags: @Fast and @Slow. To start off I have used the below maven entry to configure which test to run with my default build. This means that when I execute mvn test only my fast tests will execute. I assume I can override this using the command line. But I can not figure out what I would enter to run my slow tests....

我认为类似....mvn test -Dmaven.IncludeTags=fast,slow无效

I assumed something like.... mvn test -Dmaven.IncludeTags=fast,slow which does not work

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <properties>
            <includeTags>fast</includeTags>
            <excludeTags>slow</excludeTags>
        </properties>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.0.0-M3</version>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
            <version>1.0.0-M3</version>
        </dependency>
    </dependencies>
</plugin>

推荐答案

您可以使用以下方式:

<properties>
    <tests>fast</tests>
</properties>

<profiles>
    <profile>
        <id>allTests</id>
        <properties>
            <tests>fast,slow</tests>
        </properties>
    </profile>
</profiles>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <properties>
                    <includeTags>${tests}</includeTags>
                </properties>
            </configuration>
        </plugin>
    </plugins>
</build>

通过这种方式,您可以从mvn -PallTests test所有测试(甚至是mvn -Dtests=fast,slow test)开始.

This way you can start with mvn -PallTests test all tests (or even with mvn -Dtests=fast,slow test).

这篇关于如何选择要使用Maven执行的JUnit5标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 16:42