Maven + jUnit4:包括基于测试名称的测试

问题描述

我正在尝试根据测试用例名称从我的Test类中运行一些选定的测试。

下面是我的测试课程的概述

---- GlobalTests.java ----

@Test
public void myTest_India(){ --- }

@Test
public void myTest_Germany() { --- }

---- GlobalIntegrationTests.java ----

@Test
public void myIntegrationTest_India(){ --- }

@Test
public void myIntegrationTest_Germany() { --- }

我如何指示我的Maven仅运行“印度”测试?

我已经尝试了如下的maven surefire插件

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
                <configuration>
                    <includes>
                        <include>%regex[*Test_India*]</include>
                    </includes>                    
                </configuration>
            </plugin>

但似乎此配置用于选择测试类名称而不是测试名称。

谢谢。

解决方法

这可以通过使用maven的'test'属性来完成 可以将要运行的测试定义为testClass#testName 以下方法有效

<project>
    <properties>
        <test>*#*India</test>
    </properties>
</project>

并以

运行
mvn test

或直接在命令行中以mvn -Dtest="*#*India"

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...