java - Cucumber .feature 文件未在 Java 类中获取步骤定义
问题描述
我正在为我的 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 类中的上述步骤定义。
有人对可能出现的问题有任何建议吗?
也许这不是您应该通过示例表传递整数的方式
解决方案
匹配 step 方法的正则表达式必须匹配 step 中的文本(字面意思)。
如果你的步骤是
Then the status code should be <StatusCode>
胶水代码中的正则表达式
@Then("^the status code should be (\\d+)$")
将不匹配(因此您不能 CTRL+单击它)StatusCode
。
以下简单示例将起作用。
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 {
...
}
推荐阅读
- sharepoint - Sharepoint Online Rest API:过滤以仅显示具有版本的文件
- sql-server - 如何根据子记录获取完成状态
- java - 如何以编程方式修改可绘制角Android Java
- c++ - 如何确保调用覆盖的函数
- tally - 创建公司理货 xml 请求格式
- javascript - 在javascript中旋转360度鼠标拖动全景图像
- javascript - fullcalendar 选择事件在 iPhone XR 上不起作用
- java - 来自父 POM 的默认激活配置文件不会激活子模块中具有相同 ID 的配置文件
- android - 如何在 Kotlin 的 Room Entity 的构造函数中使用 Android 资源字符串
- python - 类型提示预期布尔值且始终为空列表