我一直在阅读JBehave文档,但我找不到任何与此特定用例有关的内容。我发现最接近参数化场景的this,但它并不是我想要的。我不需要使用不同的参数多次运行相同的逻辑,我需要使用一组参数运行步骤逻辑一次。具体来说,我需要传递数字1-4的组合。有没有办法做到这一点?
答案 0 :(得分:4)
你的意思是Tabular Parameters吗?
您可以像这样使用它:
Given the numbers:
|combinations|
|1234|
|4321|
|1324|
When ...
然后:
@Given("the numbers: $numbersTable")
public void theNumbers(ExamplesTable numbersTable) {
List numbers = new ArrayList();
for (Map<String,String> row : numbersTable.getRows()) {
String combination = row.get("combinations");
numbers.add(combination);
}
}
我刚刚重写了jBehave示例,因此它可以满足您的需求。您可以将任何组合计数传递到给定的表内,然后逐步将其转换为数组或将我的示例转换为列表。