JBehave support in JSystem

JBehave support in JSystem

The BDD approach seems to gain popularity by the minute. One of the most popular frameworks that supports it in the Java language is JBehave. As a result, you may find the need to integrate a JBehave test (story), in one of you scenarios.

If this seems to be the cases, there is a very simple way to accomplish it. You can just use the JSystem JBehave system object.

First, locate the dependencies section in your test project POM file and add the system object artifact.

<dependencies>
.
	<dependency>
		<groupId>org.jsystemtest.systemobjects</groupId>
		<artifactId>jbehave-so</artifactId>
		<version>1.0.0</version>
	</dependency>
.
.
</dependencies>

JBehave stories are composed of steps, which are Java classes and the stories which are plain text files. To run the story use the JSystemEmbedder class and specify in the class constructor all the step classes.

Invoke the runStoriesAsPathes method to execute the story.

	@Test
	public void runJBehaveStory(){
		List<Class<?>> stepClasses = new ArrayList<Class<?>>();
		stepClasses.add(MySteps.class);
		Embedder embedder = new JSystemEmbedder(stepClasses);

		List stories = new ArrayList();
		stories.add("my.story");
		embedder.runStoriesAsPaths(stories);

	}

The reports would be attached to the JSystem HTML report.

The sources of the system object can be found here. For a full example of a generic test that can execute any story browse to here.

 

View Itai Agmon's LinkedIn profileView Itai Agmon’s profile

Fork me on GitHub