方案大纲中带有多个示例表的黄瓜标记 [英] Cucumber Tagging with Multiple Examples tables in a Scenario Outline

查看:268
本文介绍了方案大纲中带有多个示例表的黄瓜标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的黄瓜方案纲要中,示例表中的一些示例正在传递,而某些示例却失败了。

In my Cucumber Scenario Outline, some of the examples in my examples table are passing, and some are failing.

我正在尝试向其中添加标签,因此我可以运行那些通过的&跳过当前失败的那些。

I am trying to add tags to these, so I can run those which pass, & skip those which are failing currently.

我试图复制一些我在网上找到的示例,但我遇到了错误。

I have tried to copy some examples I've found online, but I am getting an error.

以下是我最近的尝试:

    Scenario Outline: BR001 test
    Given...
    When...
    Then...

    @passing
    Examples:
    |     errorCode    |
    |      BRS002      |
    |      BRS003      |
    |      BRS004      |
    |      BRS005      |
    |      BRS008      |
    |      BRS010      |
    |      DE19716     |
    |      BRS006      |
    |      BRS009      |

    @failing
    Examples:                               
    |     errorCode     |
    |       DE19716     |
    |       BRS006      |
    |       BRS009      |

但是, @passing 出现错误。这是出现的错误消息:

But, there is an error with @passing. Here is the error message appearing:


不匹配的输入'@passing'期望为示例:

mismatched input '@passing' expecting 'Examples:'

我已经复制了一个在线示例,所以我不知道为什么这会引发错误?

I've copied an online example, so I don't know why this is throwing an error?

推荐答案

也许您应该再次检查依赖项。

Maybe you should check again your dependencies.

假定以下结构

src/test/java/features/userdata.feature
src/test/java/glue/StepPojo.java
src/test/java/myRunner/TestRunner.java
pom.xml

pom.xml 相关性

<properties>
    <version.cucumber>3.0.2</version.cucumber>
</properties>
<dependencies>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${version.cucumber}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${version.cucumber}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

userdate.feature -修改了方案大纲示例

方案概述:BR001测试
给出了
发生的情况
然后结果为

Scenario Outline: BR001 test Given something When happen Then result ""

...两个都标记为示例:的部分

... your both tagged 'Examples:' sections

StepPojo.java >

包装胶;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class StepPojo {

    @Given("^something$")
    public void something() throws Throwable {
        System.out.println("something");
    }

    @When("^happen$")
    public void happen() throws Throwable {
        System.out.println("happen");
    }

    @Then("^result$")
    public void result() throws Throwable {
        System.out.println("result");
    }

    @Then("^result \"([^\"]*)\"$")
    public void result(String errorCode) throws Throwable {
        System.out.println("result = " + errorCode);
    }
}

TestRunner.java

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/test/java/features/userdata.feature",
        glue = {"glue"},
        tags = {"@failing"}
)
public class TestRunner {

}

的输出mvn test

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running myRunner.TestRunner
something
happen
result = DE19716
something
happen
result = BRS006
something
happen
result = BRS009

3 Scenarios (3 passed)
9 Steps (9 passed)

这篇关于方案大纲中带有多个示例表的黄瓜标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆