【发布时间】:2015-10-07 23:02:54
【问题描述】:
我正在使用 Behat v3.0 为我的代码创建测试,但我的功能文件的场景大纲中有几个步骤仍未定义。
我的场景大纲示例:
Scenario Outline: Send email validation messages
Given I have the email <email>
When I send the email
Then the response status code should be "500"
And I get a message from the <variable> variable that reads <message>
Examples:
| email | variable | message |
| | email | The email field is required. |
| -1 | email | The email must be a valid email address. |
| email | email | The email must be a valid email address. |
我使用了http://docs.behat.org/en/stable/guides/1.gherkin.html#scenario-outlines 的文档。
为了定义步骤,我在 FeatureContext.php 中为两个问题步骤提供了步骤定义方法:“我有电子邮件
/**
* @Given I have the email :email
*/
public function iHaveTheEmail($email)
{
// Save the email address
}
/**
* @Then I get a message from the :variable variable that reads :message
*/
public function iGetAMessageFromTheVariableThatReads($variable, $message)
{
// Check the response for the validation errors
}
我使用了http://docs.behat.org/en/v3.0/guides/2.definitions.html的文档
运行 Behat 的输出坚持认为这些步骤仍未定义。只有带有与示例列表关联的参数的步骤存在此问题。步骤“响应状态代码应为'500'”按预期工作。
我找不到在场景大纲中定义步骤的具体示例,而且 Behat 的文档通常很少。
我可以像 Behat v2.5 那样使用正则表达式注释来定义步骤,但这是唯一的解决方案吗?
【问题讨论】: