2016-02-26 26 views
4

我是JBheave和Hive框架的新手。@BeforeScenario/@AfterScenario通過使用給定的測試故事中的特定方案

在探索Q &一個倉庫,我碰巧看到正確的答案的一個問題之一下列短語 -

writing a JBehave story

這是我見過的 - 和數據對象應該使用@ BeforeScenario/@ AfterScenario方法設置/清除 。

目前我正在編寫測試故事的過程。然而,沒有進一步進入步驟。

從JBehave產品網站,我得到以下樣本測試故事。我有問題,考慮從Q & 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:的。

回答

5

有@ BeforeScenario/@ AfterScenario註釋和生命週期之間的一些區別:/步驟後,之前

  1. 與@BeforeScenario或@AfterScenario註解的Java方法被稱爲在所有所有執行場景故事,而Lifecycle-Before或-After步驟將僅適用於該場景的場景,具體故事
  2. @AfterScenario方法始終執行,無論場景結果如何。生命週期以下步驟可以始終使用(使用結果:ANY子句),僅在失敗時使用(使用結果:失敗子句)或僅在成功時使用(使用結果:SUCCESS子句)
  3. 您無法從場景(故事)到@BeforeScenario和@AfterScenario Java方法,而生命週期的步驟可以具有參數,像任何其他普通的步驟,例如:

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

謝謝你的回答。然而在我的情況下,我的測試故事'then'子句可能會變得非常複雜,有幾個'和'子句以及約束條件。我需要將它作爲參數傳遞給下一個場景或一些場景。會有辦法嗎? –

+1

請詳細解釋您的具體情況,最好是作爲一個新問題 - 您想要達到什麼目的? – krokodilko

+0

如何將在故事中編寫的參數映射到使用@BeforeScenario註釋的方法? –

1

JBehave是用於數據挖掘。它使用測試驅動開發TDD。我們稱之爲步驟。 BDD - 行爲驅動開發,可以將該框架的挖掘功能注入到任何高級語言中。

回答問題 - 在一個測試故事中,如果我們將Scenario置於兩個then語句的中間,它將清除緩衝區,因爲它是一個新的場景。這樣Given子句數據集按原樣應用,而非暗示。以這種方式Given子句值被採用。對於新的Scenario只有Lifecycle已設置的先決條件分別僅適用於前後。

+0

感謝我的同事Rob爲這個疑問提供了清晰的說明!是的,我仍然努力在基於Hive的框架。再次感謝! –

相關問題