[英]BDD: Embedded tables with serenity and jbehave
I'm trying to create a BDD test with serenity (former thucydides) using the jbehave extension, this is my story (originating from the serenity jbehave examples) 我正在尝试使用jbehave扩展创建一个宁静(前thucydides)的BDD测试,这是我的故事(源自宁静的jbehave示例)
Scenario: a scenario with embedded tables
Given that I sell the following fruit
| fruit | price |
| apples | 5.00 |
| pears | 6.00 |
And I sell the following vegetables
| vegetable | price |
| potatoe | 4.00 |
| carrot | 5.50 |
When I sell fruit
Then the total cost should be total
Examples:
| goods | total |
| apples, carrot | 11.50 |
| apples, pears | 11.00 |
| potatoe, carrot | 9.50 |
The generated java code is the following: 生成的java代码如下:
@Given("that I sell the following fruit\r\n| fruit | price |\r\n| apples | 5.00 |\r\n| pears | 6.00 |")
public void givenThatISellTheFollowingFruitFruitPriceApples500Pears600() {
// PENDING
}
@Given("I sell the following vegetables\r\n| vegetable | price |\r\n| potatoe | 4.00 |\r\n| carrot | 5.50 |")
public void givenISellTheFollowingVegetablesVegetablePricePotatoe400Carrot550() {
// PENDING
}
@When("I sell fruit")
public void whenISellFruit() {
}
@Then("the total cost should be total")
public void thenTheTotalCostShouldBeTotal() {
// PENDING
}
How do I retrieve the table arguments in my test ? 如何在测试中检索表参数?
I tried the ExamplesTable
parameters as per documentation on jbehave tabular parameters but that did not work. 我按照jbehave表格参数的文档尝试了
ExamplesTable
参数,但是没有用。
Is there a way to make the given
annotation more readable (by not adding the table parameters) ? 有没有办法让给
given
注释更具可读性(通过不添加表参数)?
You can retrieve the ExampleTable
parameter like this (and have more readable given annotations): 您可以像这样检索
ExampleTable
参数(并且具有更多可读的给定注释):
@Given("that I sell the following fruit $exampleTable")
public void thatISellTheFollowingFruit(ExamplesTable exampleTable) {
System.out.println("MyTable: "+exampleTable.asString());
}
If it doesn't find the declared method and tells you that this step is pending, you could check if you have a whitespace in your story after the word fruit : 如果找不到声明的方法并告诉您此步骤处于暂挂状态,则可以在单词fruit之后检查故事中是否有空格:
Given that I sell the following fruit
How to access the several rows and columns in your tables is written in the jBehave documentation under http://jbehave.org/reference/stable/tabular-parameters.html 如何访问表中的多个行和列是在http://jbehave.org/reference/stable/tabular-parameters.html下的jBehave文档中编写的
You could also think about creating only one table instead of three: 您还可以考虑仅创建一个表而不是三个:
Scenario: a scenario with embedded tables
Given I sell <product1>
And the price is <product1price>
And I sell <product2>
And the price is <product2price>
When I sell something
Then the total cost should be <total>
Examples:
| product1 | product1price | product2 | product2price | total |
| apples | 5.00 | carrot | 6.50 | 11.50 |
| apples | 5.00 | pears | 6.00 | 11.00 |
| potatoe | 4.00 | carrot | 9.50 | 13.50
The java code would have to look like this to access the parameters: java代码必须看起来像这样才能访问参数:
@Given("I sell <product1>")
public void iSellProduct(@Named("product1") String product1) {
//do something with product1
}
Does this help? 这有帮助吗? If not, what exactly does not work when you try to read the exampleTable?
如果没有,当你尝试阅读exampleTable时究竟什么不起作用?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.