【问题标题】:jbehave - How to execute code before each example of a scenariojbehave - 如何在场景的每个示例之前执行代码
【发布时间】:2018-01-11 10:04:42
【问题描述】:

将 Serenity 与 JBehave 结合使用时,我的步骤定义将通过 @Given 和 @When 提供的信息添加到内部状态类中,该类在 @Then 方法中进行验证。

需要为每个测试重新初始化状态类,即在每个没有示例的场景之前和在有示例的场景的每个示例之前。

我怎样才能做到这一点?

我在http://jbehave.github.io/Old_JBehave_Issues/548/ 找到了请求@BeforeExample(这将解决我的问题)的JIRA 票证。但是,使用@BeforeScenario 只会在每个场景之前清除,而不是在每个示例之前。

在场景有多个 @Given 的情况下(使用 Given...And....),清除每个 @Given 中的状态将不起作用。

【问题讨论】:

    标签: bdd jbehave serenity-bdd


    【解决方案1】:

    @BeforeScenario 不起作用(在所有示例场景中被忽略)。

    @BeforeScenario(uponType = ScenarioType.ANY) 确实有效,在发布此问题之前我发现它不起作用,但显然是由其他原因引起的。

    无论哪种方式,方法都必须是公开的。

    【讨论】:

      【解决方案2】:

      您可以尝试使用 JBehave 的“之前”生命周期重置场景状态:

      Narrative:
      ...
      
      Lifecycle: 
      Before:
      Given a step that is executed before each scenario 
      

      一些额外的生命周期选项:

      Lifecycle:
      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
      

      来源:JBehave Story Syntax

      【讨论】:

        猜你喜欢
        • 2018-12-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多