Site icon TestingDocs.com

Configure JBehave Stories

Introduction

In this post, we will learn how to configure JBehave Stories. If you are a beginner to JBehave, read more here about it ( What is JBehave Framework? ).

MostUsefulConfiguration

Configuration is an abstract class that can be viewed as a Builder pattern. It provides the configuration used by the Embedder and the in the Embeddable implementations to customize the runtime properties. Also, each element of the configuration can be specified individually, and read well. Furthermore, all elements have default values, which can be overridden by the “use” methods. The “use” methods allow overriding the dependencies one by one.

MostUsefulConfiguration is a subclass of Configuration. As mentioned above, we can specify and override many use methods to alter the runtime behavior of how we configure stories and steps. For example, story loading, step finder, failure strategy, pending steps strategy etc.

 

https://www.testingdocs.com/jbehave-mostusefulconfiguration/

Adding Step Instance

I have added the step instance of the Calc story as below:

@Override
    public List<CandidateSteps> candidateSteps() {
        return new InstanceStepsFactory(configuration(), new AddSteps())
                .createCandidateSteps();
    }

 

The minimal default configuration as shown below:

 new MostUsefulConfiguration().useStoryLoader(
     new LoadFromRelativeFile(storyURL)).useStoryReporterBuilder(
     new StoryReporterBuilder().withDefaultFormats());
    }

 

Running JBehave Stories

We can run the Jbehave story in many ways using IDE’s and tools using JUnit. We can also use the Embedder class. Embedder is a facade pattern, which allows the functionality to be embedded into other run contexts, such as IDE via using JUnit,  Maven, etc.

The above configuration method loads the default configuration for running the tests. Override the Junit run method to run the story as shown below. Now running the test is simple, select Run As > JUnit Test.

@Override
    @Test
    public void run() {
        try {
            super.run();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

 

Reports

Consolidated Story report ( reports.html ) can be found under the target view folder.

 

Jbehave Story Reports

 

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