5

I am a newbie to JBheave and Hive frameworks.

While exploring Q&A repositories, I happen to see the following phrase from one of right Answer to a Question,-

writing a JBehave story

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

At present I am in the process of writing Test Stories. Yet not get into Steps further.

From the JBehave product website, I get the following sample Test Story. I have Question considering the phrase which I plugged out from the Q&A repo of 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|

I could see the pretty same just as like @BeforeScenario/@AfterScenario over here.

I do have Question here. Is I could write Given before and after to specific Scenario: in a Test Story.

And is that Scenario: output is open to consecutive Scenario:'s in the Test Story.

Community
  • 1
  • 1
Dev Anand Sadasivam
  • 699
  • 7
  • 21
  • 49

2 Answers2

7

There is a few differences between @BeforeScenario/@AfterScenario annotations and Lifecycle:Before/After steps

  1. A java method annotated with @BeforeScenario or @AfterScenario is called for all executed scenarios in all stories, while a Lifecycle-Before or -After step will be executed only for scenarios from this one, concrete story.
  2. @AfterScenario method is executed always, regardless of a result of the scenario. Lifecycle After steps can be called always (using Outcome: ANY clause), only on failures (using Outcome: Failure clause) or only on success (using Outcome: SUCCESS clause)
  3. You cannot pass any parameters from a scenario (story) to @BeforeScenario and @AfterScenario java methods, while Lifecycle steps can have parameters, like any other ordinary steps, for example:

Lifecycle:
Before:
Given a step that is executed before each scenario with some parameter = 2
krokodilko
  • 35,300
  • 7
  • 55
  • 79
  • Thanks for your good answer. However in my case my test story `then` clause may go very complicated with several `and` clause and so and so constraints. I need that to be passed as a parameter to the next scenario or some. Will there will be way for it? – Dev Anand Sadasivam Mar 01 '16 at 03:58
  • 1
    Please explain in more details your specific case, preferably as a new questions - what exactly do you want to achieve? – krokodilko Mar 01 '16 at 21:55
  • how to map a parameter written in the story to the method annotated with @BeforeScenario ? – Enrico Giurin Jun 22 '16 at 15:43
  • @EnricoGiurin you may store the parameter in some global variable and then to use it within the AfterScenario method – Igal Sep 06 '16 at 14:17
-2

JBehave is for Data Mining. And it is uses Test Driven Development, TDD. We call that as Steps. BDD - Behavior Driven Development, that yields the Mining capability of that framework injected towards any Higher-Level language.

Answering the Question,- In a test story, if we put Scenario in the mid of two then statements, it clears the buffers as it is a new scenario. That way Given clause datasets is applied as-is, rather implied. That way Given clause values are taken forward. For new Scenario only Lifecycle prerequisites which is been set is only applied on before and after respectively.

Dev Anand Sadasivam
  • 699
  • 7
  • 21
  • 49