黄瓜.feature文件未使用Java类中的步骤定义

时间:2018-11-13 17:23:52

标签: java cucumber gherkin feature-file

我正在为我的Java项目编写一些黄瓜测试。 我的测试工作正常,但是.feature文件中出现一个小的警告。

下面,我将.feature文件中的整数传递到单独的Java类的“步骤定义”中

.feature文件中,在下面的步骤下出现一条黄色的弯曲线:

Then the status code should be <StatusCode>

我收到的警告消息是:

  

找不到the status code should be

的定义

这是我的特征文件示例表:

| StatusCode |
| 200        |

下面是我的步骤定义:

@Then("^the status code should be (\\d+)$")

此错误使我无法通过 Ctrl +单击' Then '语句将我带到上述Java类中的步骤定义。

有人对可能出什么问题有任何建议吗?

也许这不是您应该通过示例表传递整数的方式

1 个答案:

答案 0 :(得分:0)

与step方法匹配的正则表达式必须与步骤中的文本(字面上)匹配。

如果您的步骤是

Then the status code should be <StatusCode>

粘合代码中的正则表达式

@Then("^the status code should be (\\d+)$")

不匹配StatusCode。(因此,您无法CTRL +单击它)。

下面的简单示例将起作用。

Scenario Outline: outline
  Given something
  Then the status code should be <StatusCode>
  Examples:
    | StatusCode |
    | 200        |

和链接的步骤定义

@Then("^the status code should be ([^\"]*)$")
public void theStatusCodeShouldBe(String statusCode) throws Throwable {
    ...
}

编辑:如果要将状态代码传递为Integer,则可以将步骤定义的签名更改为

@Then("^the status code should be ([^\"]*)$")
public void theStatusCodeShouldBe(Integer statusCode) throws Throwable {
    ...
}