This article is the first of a three-part series about developing behavior-driven tests for JEE web applications with Jbehave.
Behavior-driven development, or BDD, is an agile software development process providing developers, QA, project managers and business teams with a shared tool-set and process for software development collaboration.
In this guide, we’ll learn how to design, develop and automate Black-box tests for a JEE web application using BDD. We’ll do so while developing on top of a Jbehave framework.
Set out below are the explanations of the main terms used in this blog.
According to Wikipedia, “Black-box testing is a method of software testing that examines the functionality of an application without peering into its internal structures or workings”. As such, Black-box testing focuses entirely on the inputs and outputs of the software system – the “black box”.
Behavior-driven development is an extension of test-driven development that makes use of a simple, domain-specific scripting language.
In BDD, you describe what you want the system to do, by talking through example behavior. Work from the outside-in to implement those behaviors using examples to validate “you are what you are building”.
The customer (perhaps a Scrum Product Owner) describes what they want and the developers ask questions to flesh out enough detail about the behavior to be able to implement it”. (BDD in a nutshell).
Structure:
JBehave is an open-source framework for behavior-driven development. It supports Java-based development, and plain English is used to form the story.
The steps in the story are visually linked to a corresponding Java method:
JBehave supports multiple mechanisms for parameter injection. In the above example, the ‘user’ and ‘password’ are arguments extracted from the @When step, with the @named annotation, following a natural order to the parameters in the annotated Java method.
In addition, Jbehave provides an easy way to create more intelligent data types than these strings. There are multiple plugins for generating comprehensive and interactive reports.
There are many (many!) advanced features that are worth checking out (see advanced topics on the Jbehave site); we’ll only be using a few of them.
We’ll explain how Jbehave works at a lower level later.
Thucydides is a tool designed to make writing automated acceptance tests easier.
Thucydides and JBehave work well together. Thucydides uses simple conventions to make it easier to get started with writing and implementing JBehave stories. It reports on both JBehave and Thucydides steps, which can be seamlessly combined in the same class.
We use Idea IntelliJ-IDE with the ‘Jbehave support’ plugin for writing the stories and the code behind it.
‘Volcano’ is intended to be a social network for Volcano enthusiasts.
The project manager of ‘Volcano’ would like to add some basic features and behaviors:
Each feature is described in it’s own Jbehave story file.
Here is how the “Registration” story appears before applying the Jbehave support plugin:
And after applying the Jbehave support plugin:
At this stage the steps are marked in red, and we receive a message when the mouse hovers over it, that there is no Java method that linked with the steps.
Here Thucydides kicks in.
We’ll use the ‘net.thucydides’ libraries for the implementation.
The following Jbehave plugin artifact:
This includes the Jbehave libraries that are required for the Java implementation code behind it:
Jbehave-core provides the basic Jbehave BDD building blocks: The @Given @When @Then Annotations, and the annotations responsible for the parameter injection (i.e. @Named) ‘Jbehave-junit-runner’ provides functionality for the story and scenarios lifecycle and reporting.
Later on, we’ll use it to identify the stories and run the test.
In Part II we’ll implement the ‘Registration’ story, and review solutions to the implementation challenges.