问题描述
我正在努力实现这一目标:我想配置一个maven项目,以便它根据所选的配置文件(dev | pro)运行黄瓜功能的不同子集
I am strugging to achieve this: I want to configure a maven project so that it runs different subsets of the cucumber features depending on the selected profile (dev | pro)
例如,我有几个功能文件来测试Web导航,使用标签指定环境:
For instance, I have a couple of feature files to test web navigation, using tags to specify the environment:
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类,每种环境一个:
I created two Test java classes, one for each environment:
普通基础班:
@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
时,它显然会同时运行两个测试类,并且每个测试类都会测试其相应的标记功能.如何使用配置文件选择标签,以便仅执行其中一个测试类?
When I run mvn test -Dtest-groups=cucumber
it obviously runs both test clases, and each will test its corresponding tagged feature. How can I select the tag using a profile so that only one of the test classes executes?
推荐答案
最终,我想出了在使用配置文件时如何传递黄瓜标签配置的方法:
Eventually, I figured out how to pass cucumber the tag configuration when working with profiles:
<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
来限制要根据环境运行的方案/功能.
With this I can invoke mvn test -Dtest-groups=cucumber -Denvironment=dev
to limit the scenarios/features that I want to run depending on the environment.
这篇关于Maven + Cucumber-jvm-如何根据环境运行功能的不同子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!