2015-07-10 3 views
1

Я пытаюсь создать тест BDD с безмятежностью (бывший Фукидид), используя JBehave расширения, это моя история (происходящая из безмятежности JBehave примеров)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 | 

Сгенерированный код 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 
} 

Как получить аргументы таблицы в своем тесте?

Я пробовал параметры ExamplesTable в соответствии с документацией по табличным параметрам jbehave, но это не сработало.

Есть ли способ сделать примечание given более читаемым (не добавляя параметры таблицы)?

ответ

3

Вы можете получить параметр ExampleTable как это (и имеют более читаемые данные аннотаций):

@Given("that I sell the following fruit $exampleTable") 
public void thatISellTheFollowingFruit(ExamplesTable exampleTable) { 
    System.out.println("MyTable: "+exampleTable.asString()); 
} 

Если он не находит заявленный способ и говорит вам, что этот шаг в ожидании, вы можете проверить, если у вас есть пробелы в вашей истории после слова фруктового:

Given that I sell the following fruit 

Как получить доступ к несколько строк и столбцов в таблицах написано в документации JBehave под http://jbehave.org/reference/stable/tabular-parameters.html

Вы могли бы также подумать о создании только один стол вместо трех:

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 

Java-код должен был бы выглядеть так, чтобы получить доступ к параметрам:

@Given("I sell <product1>") 
public void iSellProduct(@Named("product1") String product1) { 
    //do something with product1 
} 

Поможет ли это? Если нет, что именно не работает, когда вы пытаетесь прочитать exampleTable?

+0

Я попробовал несколько способов ввода '$ exampleTable' в мой метод, но я думаю, что я использовал' 'и не удалял конец сгенерированного имени метода (... FruitPriceApples500Pears600) – phury

+0

Я хотел первый пример для работы, потому что я использую json в своих табличных данных и ввод нескольких json-объектов в строке на самом деле не читается – phury

Смежные вопросы