Maven和JUnit 5:在一个类中运行单个测试

时间:2017-08-28 13:10:38

标签: maven junit5

我一直尝试使用Maven(版本3.3.9)和JUnit 5(不是4)使用以下命令在一个类中运行单个测试失败:

mvn -Dtest=EmitRulesTest#cr_filter_contact_points_for_C4C_output test

此命令执行所有测试。

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

mvn test -Dtest=EmitRulesTest

这是我的JUnit 5 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

1 个答案:

答案 0 :(得分:0)

您可以使用以下格式:

DELETE

您可以在此处找到更多信息:importlib._bootstrap.FileFinder.find_spec

这是我的POM.xml的摘录

mvn test -Dtest=TestClass#testMethod