我正在努力实现这一目标:我想配置一个 Maven 项目,以便它根据所选配置文件运行不同的 Cucumber 功能子集 (dev | pro)
例如,我有几个功能文件来测试网络导航,使用标签来指定环境:
PRO
@pro
Feature: Nav Pro
Scenario: navigate to home
Given access /
Then it should be at the home page
DEV
@dev
Feature: Nav Dev
Scenario: navigate to login and log user correctly
Given access /login
When the user enters xxxx yyyy
Then it should be logged
我创建了两个 Test java 类,每个环境一个:
通用基类:
@Test(groups="cucumber")
@CucumberOptions(format = "pretty")
public class AbstractBddTest extends AbstractTestNGCucumberTests {
PRO
@Test(groups="cucumber")
@CucumberOptions(tags={"@pro", "~@dev"})
public class ProTest extends AbstractBddTest{}
DEV
@Test(groups="cucumber")
@CucumberOptions(tags={"@dev", "~@pro"})
public class DevTest extends AbstractBddTest{}
Maven cfg 摘录:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>${test-groups}</groups>
</configuration>
</plugin>
...
<properties>
<test-groups>unit,integration</test-groups>
</properties>
当我跑步时mvn test -Dtest-groups=cucumber
显然它运行两个测试类,并且每个测试类都会测试其相应的标记功能。如何使用配置文件选择标签以便仅执行一个测试类?