@BeforeStories / @AfterStories JBehave Annotations
Overview
In this post, we will discuss Jbehave annotations @BeforeStories and @AfterStories . If you are familiar with the TestNG framework these annotations are somewhat similar to @BeforeSuite and @AfterSuite.
@BeforeStories and @AfterStories
The @BeforeStories and @AfterStories annotations allow the methods to be executed before and after stories respectively. Also, any initialization code before executing stories goes into @BeforeStories method. In addition, any clean-up code that needs to be run after all the stories have run goes into @AfterStories. Furthermore, the below picture attempts to clarify the concept.
Any initialization setup code should be written in this annotated method. For example, opening a db connection, reading and setting Jbehave configuration etc…
Example code snippet
@BeforeStories public void storiesInit() { System.out.println("BeforeStories......"); // initialization setup code goes here …. This code executes before all stories // for example you may open a db connection etc... }
@AfterStories public void storiesCleanUp() { System.out.println("AfterStories......"); // cleanup code goes here …. This code executes after all stories have run // for example you may archive run reports , close db connection etc... }
All the cleanup code should go here in this code block. This code executes after all the stories have run. Examples that go here are closing db connections , archiving the results , sending stats metrics, any clean up code that you may be interested in
JBehave Tutorials on this website can be found at:
https://www.testingdocs.com/jbehave-framework-tutorial/
For more details on the JBehave framework, visit the official JBehave website at:
http://jbehave.org