我是黄瓜新手。我要求在功能文件示例中使用变量而不是实际值。实际值将填充在单独的属性文件中。
示例功能文件:
@tag Feature: Add an element to stack The user pushes an element. It gets added to stack @tag1 Scenario: Push element to empty stack Given Stack is empty When User pushes an element Then stack should have only one element @tag2 Scenario Outline: Push element to stack Given Stack has {initial} elements When User adds {new} element Then Length of stack increases to {new_size} | initial | new | new_size | | 1 | 2 | 2| | 5 | 9 | 6| | 0 | 3 | 1|
输出示例应为:
| initial | new | new_size | | {val1_1} |{val1_2} | {val1_3}| | {val2_1} |{val2_2} | {val2_3}|
我使用了“ {}”而不是“ <>”,因为无法以预先格式化的代码打印<>中的元素
答案 0 :(得分:1)
使用场景大纲和示例。它会为您解决基于数据输入的查询。例如,
@tag2
Scenario Outline: Push element to stack
Given Stack has <initial> elements
When User adds <new> element
Then Length of stack increases to <new_size>
Examples:
| initial | new | new_size |
| 1 | 2 | 2 |
| 5 | 9 | 6 |
| 0 | 3 | 1 |
您的步骤定义将是这样,
Given("^Stack has (.*) elements$", (String initial) -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
类似地对其他查询参数(例如,(名称,new_size))进行操作。