本文介绍了Maven + Cucumber-jvm - 如何根据环境运行不同的功能子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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?

解决方案

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.

这篇关于Maven + Cucumber-jvm - 如何根据环境运行不同的功能子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-20 00:43