I'm using Cucumber in Java, and have written a scenario that takes a List
as an argument, i.e.
And the following ids are within the range: 1, 2
This works successfully with the method definition:
@Given("^the following ids are within the range: (.*)$")
public void ids_are_within_range(List<String> idsWithinRange) {
this.idsWithinRange = idsWithinRange
}
However I have a problem if I try to pass no IDs into the list:
And the following ids are within the range:
The test simply doesn't execute and tells me I need to implement the relevant test methods. It thinks that the line ending in a list is actually a different method that doesn't take any arguments:
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:$")
How do I get an empty List
to be passed into my method?
As a workaround (not an elegant solution), you could set your step definition as follows:
And the following ids are within the range: ,
You'll receive an initialized empty ArrayList
in your method.
Hope it helps. Anyway, I'll be waiting for other answers, maybe someone can give a better solution.