使用空List参数在Gherkin中创建Cucumber特征

时间:2015-12-15 12:31:49

标签: java cucumber cucumber-jvm gherkin

我在Java中使用Cucumber,编写了一个以List为参数的场景,即

And the following ids are within the range: 1, 2

这对方法定义成功:

@Given("^the following ids are within the range: (.*)$")
public void ids_are_within_range(List<String> idsWithinRange) {
    this.idsWithinRange = idsWithinRange
}

但是,如果我尝试不将ID传递到列表中,则会出现问题:

And the following ids are within the range: 

测试根本没有执行,并告诉我需要实现相关的测试方法。它认为以列表结尾的行实际上是一种不采用任何参数的不同方法:

Wrong test finished. Last started: [] stopped: Scenario: Search for manifests, none of which are within a date range in the data platform; class org.junit.runner.Description
Test '.Feature: Restful CRUD service for manifest searches.Scenario: Search for manifests, none of which are within a date range in the data platform' ignored
...
You can implement missing steps with the snippets below:
...
@Given("^and the following ids are within the range:$")

如何将空List传递给我的方法?

1 个答案:

答案 0 :(得分:1)

作为解决方法(不是优雅的解决方案),您可以按如下方式设置步骤定义:

And the following ids are within the range: ,

您的方法中会收到初始化的空ArrayList。 希望能帮助到你。无论如何,我会等待其他答案,也许有人可以提供更好的解决方案。