如何在故事文件中设置对象?

时间:2015-02-17 17:15:58

标签: java jbehave

我使用JBehave来测试我的代码。

以下是故事中的代码段

Scenario: I pass the correct data to calculator
When the given data is ABC
Then the result entity should look like
|a|100|
|b|200|

这是我的实体类。

class ResultEntity {
    private int a;
    private int b;
    // getter/setters
}

然后方法

@Then("the result entity should look like $")
public void thenTheResultEntityShouldLookLike(ResultEntity resultEntity) {
    // some code
}

如何在*.story文件中设置我的结果实体?

1 个答案:

答案 0 :(得分:0)

故事可能看起来像这样

Scenario: I pass the correct data to calculator
When the given data is <entity>
Then the result entity should look like <value>
Examples:
|entity|value|
|a|100|
|b|200|

“Then”方法应该看起来像这样

@Then("the result entity should look like <entity>")
public void thenTheResultEntityShouldLookLike(@Named("entity") ResultEntity resultEntity) {
    // some code
}