问题
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)
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
I created two Test java classes, one for each environment:
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 excerpt:
<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>
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?
回答1:
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>
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.
来源:https://stackoverflow.com/questions/35863929/maven-cucumber-jvm-how-to-run-different-subset-of-the-features-depending-on