Maven和JUnit5:在一个类中运行一个测试 [英] Maven and JUnit 5: run a single test in a class

查看:21
本文介绍了Maven和JUnit5:在一个类中运行一个测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直尝试使用Maven(版本3.3.9)和JUnit5(而不是4)在一个类中使用以下命令运行单个测试,但未成功:

mvn -Dtest=EmitRulesTest#cr_filter_contact_points_for_C4C_output test

此命令执行所有测试。

尝试此命令实际上会执行类中的所有测试:

mvn test -Dtest=EmitRulesTest

这是我的JUnit5 Maven配置:

<dependencies>
    ...
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-params</artifactId>
        <version>5.0.0-RC2</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        ...    
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <configuration>
                <systemPropertiesFile>${basedir}/src/test/resources/definitions/system.properties</systemPropertiesFile>
                <includes>
                    <include>**/*Test.java</include>
                </includes>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider</artifactId>
                    <version>1.0.0-RC2</version>
                </dependency>
                <dependency>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-engine</artifactId>
                    <version>5.0.0-RC2</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

其他参考文献:Running a Single Test using Maven

推荐答案

您可以使用以下格式:

mvn test -Dtest=TestClass#testMethod

您可以在此处找到更多信息:http://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html

这是我的POM.xml摘录

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>${junit.jupiter.version}</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>${junit.version}</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>${junit.jupiter.version}</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.vintage</groupId>
    <artifactId>junit-vintage-engine</artifactId>
    <version>${junit.vintage.version}</version>
    <scope>test</scope>
</dependency>

...

<properties>
    <junit.version>4.12</junit.version>
    <junit.jupiter.version>5.1.0</junit.jupiter.version>
    <junit.vintage.version>5.1.0</junit.vintage.version>
    <junit.platform.version>1.1.0</junit.platform.version>
</properties>

这篇关于Maven和JUnit5:在一个类中运行一个测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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