Running Stories

JBehave was designed to be embeddable in different development environments. The JBehave Core module contains support for running stories as JUnit tests - which can be run either in your favourite IDE or in your command-line build that supports JUnit tests. Other unit testing frameworks, e.g. TestNG, can also be used very easily, c.f. FAQ.

You can also run stories using the JBehave Ant or Maven extensions. Both support two way to lookup stories, by list of story classes or by Java path includes/excludes pattern. Below are examples on how to configure both extensions - using the trader example.

Running via JUnit

Ensure the RunnableStory implementation extends JUnitStory or JUnitStories. You can also use an instance of RunnableStoryDelegator via a composition design if you prefer to extend other unit-test frameworks or JUnit-support tools that require a different hierarchical structure. In this case, you'll need to ensure that the method runStory() is invoked.

If extending JUnitStories you'll need to implement the abstract method to specify the story paths that need to run via the same RunnableStory instance:

Running as Ant task

Remember to include jbehave-ant to your runtime classpath.

Note: we are using as default scope compile, which means that the stories will be looked up in the source directory (which can be optionally specified and defaults to src/main/java). If the scope is set to test the stories will be looked up in the test source directory (which can be optionally specified and defaults to src/test/java).

Running as Maven Plugin

Note: we are using as default scope compile, which means that the stories will be looked up in the POM source directory. If the scope is set to test the stories will be looked up in the POM test source directory.

Instantiating RunnableStory classes with injected ClassLoader

Both Ant and Maven can be configured to instantiate the RunnableStory class via a public constructor with a single ClassLoader parameter (i.e. with property classLoaderInjected set to true).

Running Stories for reports

By default, the story runners are configured to fail-fast, i.e. the execution will stop at first failure (but will complete execution of the all the stories in the story or textual story file). To allow the generation of complete reports view, the runners need to be enabled to execute story in batch and ignoreFailure modes (i.e. setting these flags to true). In this way all stories will run and the build will be nominally successful but a full report can ben generated, including the failed and pending steps. Note that the batch mode is strictly speaking not essential but makes it easier to get a summary of the failed stories.