【问题标题】:Create a Cucumber feature in Gherkin with an empty List argument使用空 List 参数在 Gherkin 中创建 Cucumber 功能
【发布时间】:2015-12-15 12:31:48
【问题描述】:

我在 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 传递到我的方法中?

【问题讨论】:

    标签: java cucumber cucumber-jvm gherkin


    【解决方案1】:

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

    And the following ids are within the range: ,
    

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

    【讨论】:

    • 我喜欢这样 - 我不认为它太难看,因为逗号清楚地表明它是一个列表,而不是实际上什么都没有。它有效。谢谢!
    • 在我看来,这种解决方法(以及问题本身)要求重新考虑这些场景。如果您有一个提供了一些 id 值的场景,以及一个没有提供 id 值的场景,那么这应该是两种场景,一个是“没有提供 id 值”,或者一些这样的措辞.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    • 2021-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多