@BeforeScenario/@AfterScenario到测试故事中的特定场景使用Given

Dev*_*vam 5 jbehave

我是JBheave和Hive框架的新手.

在探索Q&A存储库时,我碰巧看到以下短语来自对问题的正确答案之一, -

写一个JBehave的故事

这就是我所见过的 - 应该使用@ BeforeScenario/@ AfterScenario方法设置/清除数据对象.

目前我正在撰写测试故事.然而,没有进一步进入步骤.

从JBehave产品网站,我得到以下示例测试故事.考虑到我从StackOverFlow的Q&A回购中插入的短语,我有问题.

A story is a collection of scenarios

Narrative:
In order to communicate effectively to the business some functionality
As a development team
I want to use Behaviour-Driven Development

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

Scenario:  A scenario is a collection of executable steps of different type

Given step represents a precondition to an event
When step represents the occurrence of the event
Then step represents the outcome of the event

Scenario:  Another scenario exploring different combination of events

Given a [precondition]
When a negative event occurs
Then a the outcome should [be-captured]   

Examples:
|precondition|be-captured|
|abc|be captured    |
|xyz|not be captured|
Run Code Online (Sandbox Code Playgroud)

就像@ BeforeScenario/@ AfterScenario在这里一样,我可以看到相同的东西.

我在这里有问题.我是否可以在测试故事中Given前后编写具体内容Scenario:.

并且该Scenario:输出是否Scenario:在测试故事中连续打开.

kro*_*lko 7

@ BeforeScenario/@ AfterScenario注释和生命周期:前/后步骤之间存在一些差异

  1. 对于所有故事中的所有已执行方案,将调用使用@BeforeScenario或@AfterScenario注释的java方法,而将仅针对来自此具体故事的方案执行Lifecycle-Before或-After步骤.
  2. 无论场景的结果如何,始终执行@AfterScenario方法.生命周期可以始终调用步骤(使用Outcome:ANY子句),仅在失败时使用(使用Outcome:Failure子句)或仅在成功时调用(使用Outcome:SUCCESS子句)
  3. 您不能将任何参数从场景(故事)传递到@BeforeScenario和@AfterScenario java方法,而Lifecycle步骤可以具有参数,就像任何其他普通步骤一样,例如:

Lifecycle:
Before:
Given a step that is executed before each scenario with some parameter = 2
Run Code Online (Sandbox Code Playgroud)