1

在 JBehave 中,可以在 Step 级别添加 BeforeStory 或 AfterStory 注释。因此,如果有多个带有 BeforeStory 注释的 Steps 类,则所有那些带有 BeforeStory 注释的方法都将在每个故事开始之前执行(这不是必需的)。

在 JUnit 中,我们可以根据需要在测试类中分别添加或保留 BeforeClass 或 Before。所以我需要一种在故事级别添加 BeforeStory 或 AfterStory 的方法,就像 JUnit 测试类一样。

有没有办法在故事文件中添加 BeforeStory 作为生命周期?或任何替代解决方案?

以下示例仅显示在生命周期中添加 Before。

http://jbehave.org/reference/stable/story-syntax.html

Lifecycle: 
Before:
Given a step that is executed before each scenario 
After:
Outcome: ANY    
Given a step that is executed after each scenario regardless of outcome
Outcome: SUCCESS 
Given a step that is executed after each successful scenario
Outcome: FAILURE 
Given a step that is executed after each failed scenario

谢谢。

4

2 回答 2

0

在我看来,jbehave 目前还没有这样的设施。但请尝试以下操作 - 在类文件中执行一个 Given 来初始化用户,并在故事场景结束时定义另一个 Given 以释放资源。我知道这种方法打破了整体和业务定义场景的 BDD 范式,但至少是一种解决方法。为确保它首先执行和最后执行,您可以对 initUsers() 使用 (priority=1),对 cleanup() 使用 (priority=n)。

于 2016-10-19T14:45:04.787 回答
0

正如您从文档中引用的那样,在每个场景之后执行之前和之后的步骤,而不是如上所述的步骤。无法在故事文件中定义“故事之前”步骤。

在故事文件中定义某些内容的另一种方法是使用 @BeforeStory 注释方法,如下所述:http: //jbehave.org/reference/stable/annotations.html

于 2017-05-20T12:36:17.533 回答