我一直在阅读 JBehave 文档,但没有找到任何与此特定用例相关的内容。我找到的最接近的是 this在参数化场景中,但这并不是我想要的。我不需要使用不同的参数多次运行相同的逻辑,我需要使用一组参数运行一次步骤逻辑。具体来说,我需要传递数字 1-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 示例,因此它可以满足您的需求。您可以将任意数量的组合传递到给定、when、then 步骤内的表中,并将其转换为数组或在我的示例中转换为列表。
关于java - 在 JBehave 中,如何将数组作为参数从故事文件传递到步骤文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32572442/