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

标签 jbehave

我是 JBheave 和 Hive 框架的新手。

在探索问答存储库时,我碰巧从正确的问题答案之一中看到了以下短语,-

writing a JBehave story

That's what I've seen - and the data object should be setup/cleared with a @BeforeScenario/@AfterScenario method.



目前我正在编写测试故事。但不要进一步进入步骤。

从 JBehave 产品网站,我得到了以下示例测试故事。考虑到我从 StackOverFlow 的问答库中插入的短语,我有疑问。
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|

我可以在这里看到与@BeforeScenario/@AfterScenario 一样的内容。

我在这里有问题。我能写吗Given前后要具体Scenario:在测试故事中。

那是Scenario:输出对连续开放 Scenario:在测试故事中。

最佳答案

@BeforeScenario/@AfterScenario 注释和 Lifecycle:Before/After 步骤之间存在一些差异

  • 用@BeforeScenario 或@AfterScenario 注释的java 方法称为所有 执行场景在所有故事中 ,而 Lifecycle-Before 或 -After 步骤将仅在场景 中执行从这个开始,具体的故事 .
  • @AfterScenario 方法总是被执行,不管场景的结果如何。 Lifecycle After 步骤可以始终调用(使用 Outcome: ANY 子句),仅在失败时(使用 Outcome: Failure 子句)或仅在成功时(使用 Outcome: SUCCESS 子句)
  • 您不能将场景(故事)中的任何参数传递给 @BeforeScenario 和 @AfterScenario java 方法,而 Lifecycle 步骤可以像任何其他普通步骤一样具有参数,例如:

  • Lifecycle:
    Before:
    Given a step that is executed before each scenario with some parameter = 2
    

    关于jbehave - @BeforeScenario/@AfterScenario 使用 Given 到测试故事中的特定场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35646024/

    相关文章:

    JBehave 调用了错误的 @When 步骤

    groovy - 从gradle运行JBehave?

    java - 通过捕获失败步骤的失败原因,继续在 Serenity Jbehave BDD 中执行后续步骤

    java - 使用 webdriver API 实现 BDD (JBehave+Webdriver)

    java - 您可以将 TestNG 的数据提供程序与 JBehave 一起使用吗?

    intellij-idea - "In order to run a story file you need to first set a main class in the JBehave settings"intellij

    java - 获取 "java.lang.NoClassDefFoundError: org/junit/platform/engine/DiscoverySelector"尝试运行 Serenity JBehave

    java - 如何跳过 Jbehave 测试的特定场景?

    java - JBehave 是否像 Jasmine 一样工作?