我正在努力实现这个目标:我想配置一个maven项目,以便根据所选的配置文件运行不同的黄瓜功能子集(dev | pro)
例如,我有几个功能文件来测试Web导航,使用标签来指定环境:
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类,每个环境对应一个:
COMMON BASE CLASS:
@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
时,它显然会运行两个测试条目,并且每个都将测试其相应的标记功能。如何使用配置文件选择标记,以便只执行其中一个测试类?
答案 0 :(得分:3)
最后,我想出了在处理配置文件时如何将黄瓜标记配置传递给它:
<profiles>
<profile>
<id>environment_dev</id>
<activation>
<property>
<name>environment</name>
<value>dev</value>
</property>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>${test-groups}</groups>
<systemPropertyVariables>
<cucumber.options>--tags @dev</cucumber.options>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
有了这个,我可以调用mvn test -Dtest-groups=cucumber -Denvironment=dev
来限制我想要运行的场景/功能,具体取决于环境。