我试图在场景大纲中只写一个变量的小黄瓜。我看到一个错误"1超出长度范围"。当我尝试运行我的特性文件时。但是,如果我添加第二个变量(另一个列和另一个变量),这将通过。
是否有一种方法来编写场景大纲只有一个变量,而不是两个或更多?如果有,怎么做?
谢谢!
示例
Feature: Is this a valid fruit?
Scenario Outline: Is this a fruit
When I ask whether <fruit> is a fruit
Then I should see "Yes this is a fruit" message
Examples:
| fruit |
| Kiwi |
| Apple |
| Pineapple |
Gives me an error "1 out of bounds for length"
我可以将其更改为以下格式并通过,但我想避免添加具有相同字符串的整个列只是为了使Cucumber Gherkins通过。
例B
Feature: Is this a valid fruit?
Scenario Outline: Is this a fruit
When I ask whether <fruit> is a fruit
Then I should see <message> message
Examples:
| fruit | message
| Kiwi | "Yes this is a fruit"
| Apple | "Yes this is a fruit"
| Pineapple | "Yes this is a fruit"
我们如何使示例A有效并通过?谢谢!
这是我对Cucumber 7.4.1的工作:
package so;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
public class StepDef {
@When("I ask whether {word} is a fruit")
public void i_ask_whether_kiwi_is_a_fruit(String value) {
System.out.println(value);
}
@Then("I should see {string} message")
public void i_should_see_message(String string) {
System.out.println(string);
}
}
这个特性文件:
Feature: Is this a valid fruit?
Scenario Outline: Is this a fruit
When I ask whether <fruit> is a fruit
Then I should see "Yes this is a fruit" message
Examples:
| fruit |
| Kiwi |
| Apple |
| Pineapple |
给:
Kiwi
Yes this is a fruit
Apple
Yes this is a fruit
Pineapple
Yes this is a fruit