我在RestAssured中使用Cucumber插件来编写我的功能文件并自动化REST服务。以下是我的方案的样子
Scenario Outline: Validate the elements in the GET response
Given I have the data setup to test "<version>" and "<order>"
When ...
Then the response should contain accurate data
Examples:
| version | order |
| V1 | O1 |
| V2 | O2 |
我的步骤定义具有以下方法签名:
@Given("^I have the data setup to test \"([^\"]*)\" and \"([^\"]*)\"$")
public void iHaveTheDataSetupToTestAnd(String clientCharacteristicTypeCd, String clientCharacteristicDataType)
我的问题是我希望在下面有另一种情况,我希望利用相同的上述步骤定义,但将附加参数“特殊订单”作为可选项传递。 我可以这样做,还是我需要为下面的给定步骤创建一个新的步骤定义?我在考虑方法重载/传递可选参数但不确定它是否在Gherkin中有效。像这样的东西
Ex:
Scenario Outline: Validate the elements in the GET response for special order
Given I have the data setup to test "<version>" and "<order>" and "<specialorder>"
When ...
Then the response should contain accurate data
Examples:
| version | order | specialorder
| V1 | O1 | SO1
| V2 | O2 | SO2
public void iHaveTheDataSetupToTestAnd(String clientCharacteristicTypeCd, String clientCharacteristicDataType, String specialOrder)
答案 0 :(得分:3)
您想要的是委托给支持这两个步骤的帮助程序。然后实现两个步骤,这些步骤不仅仅是捕获调用并将其转发给帮助程序。
这将允许您在步骤类中没有很多逻辑的情况下执行各种有趣的事情。在我的情况下,每一步通常只有一两行,我抓住参数并将它们转发给一个帮助器,在那里驱动被测系统的所有有趣的事情发生。