Site icon TestingDocs.com

Running JBehave Stories : JUnitStory and JUnitStories

JUnitStory

In this post, we will discuss running JBehave stories with JUnitStory / JUnitStories. It is a JUnit runnable entry-point to run a single story specified by a Embeddable class. JUnitStory is an abstract class and extends ConfigurableEmbedder.

public abstract class JUnitStory extends ConfigurableEmbedder { ….

 

 

Run JBehave Stories

JUnitStories

JUnit-runnable entry-point to run multiple stories specified by storyPaths(). It is similar to JUnitStory class.

public abstract class JUnitStories extends ConfigurableEmbedder { …..

 

The difference between the two is how they run Stories using the below statement:

embedder.runStoriesAsPaths(….);

 

run() method

To run the stories, we can either extend the abstract implementation of ConfigurableEmbedder,  which does not implement the run() method, or JUnitStory/JUnitStories. These classes implement run() using JUnit’s @Test annotation. However, we can also override these implementations of the run() method.

Sample code snippet

@RunWith(value=AnnotatedEmbedderRunner.class)
@UsingEmbedder(embedder=Embedder.class)
@Configure( storyReporterBuilder=MyReporter.class, storyLoader=MyStoryLoader.class)
@UsingSteps(instances={ MyStorySteps.class })

public class MyCustomStories extends JUnitStories {
    
    @Test
    @Override
    public void run() throws Throwable {
    
        // finding stories and running them 
        
    }

}

 

AnnotatedEmbedderRunner

AnnotatedEmbedderRunner is a JUnit Runner that uses the AnnotationBuilder to create an embeddable test instance.

public class AnnotatedEmbedderRunner extends BlockJUnit4ClassRunner {…..

AnnotationBuilder is a class that allows the building of Configuration, CandidateSteps, and Embedder from an annotated class as shown in above code snippet annotations.

 

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

Exit mobile version