Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

BDD and Automated Acceptance Testing for Java Web Apps: Creating a Suite

Learn how to implement some automated acceptance criteria for your Behavior Driven Development.


advertisement

Part 1 of this two-part series explained automated acceptance testing for Java Web applications using using JBehave, Thucydides and Selenium 2/Webdriver. This final installment demonstrates how to start implementing some automated acceptance criteria. To follow along, you can clone the github repository for the sample project.

Alternatively, if you want to create your own brand new Thucydides test suite and write your own tests, you can use the Maven archetype. From the command line, run mvn archetype:generate -Dfilter=thucydides-jbehave, as illlustrated below:

mvn archetype:generate -Dfilter=thucydides-jbehave
...
Choose archetype:
1: remote -> net.thucydides:thucydides-jbehave-archetype 
     (Thucydides automated acceptance testing project using Selenium 2, JUnit and JBehave) Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 1 Choose net.thucydides:thucydides-jbehave-archetype version: 1: 0.9.87 2: 0.9.88 3: 0.9.89 4: 0.9.90 Choose a number: 4: Define value for property 'groupId': : com.acme.myapp Define value for property 'artifactId': : mywebtests Define value for property 'version':  1.0-SNAPSHOT: : Define value for property 'package':  com.acme.myapp: : Confirm properties configuration: groupId: com.acme.myapp artifactId: mywebtests version: 1.0-SNAPSHOT package: com.acme.myapp  Y: :


In both cases, the project structure should look something like the one in Figure 1.

The sample project directory structure.
Figure 1: The sample project directory structure.

This directory structure follows standard Maven conventions. The JBehave stories are stored in the src/test/resources/stories directory, in a simple directory structure that reflects the organization of the requirements into capabilities and features. In the src/test/java directory, you will find the JBehave test harness (the AcceptanceTestSuite class) as well as any JBehave step implementation classes.

In the src/main/java directory, we find the Thucydides step classes and page objects. Placing these classes in the src/main/java is a relatively arbitrary choice, based on the following reasoning:

  • This maven project (or module) is dedicated to acceptance tests - if the acceptance tests are stored in the same project as the application code, this choice obviously makes less sense.
  • Page Objects and Thucydides steps are occasionally reused between related acceptance test projects, and can therefore be viewed as deliverables rather than test code: for example, page objects and steps related to integration with PayPal might be reused for several projects.

Automating Requirements and Acceptance Criteria

While JBehave helps document and automate the acceptance criteria themselves, Thucydides also reports on the features and capabilities being delivered. This helps give better context for the individual acceptance criteria as well as more relevant aggregate reporting. In this project, the capabilities are represented as directories underneath the src/test/resources/stories directory. The features are represented by JBehave stories directly in these directories; for a more complexe application, we might have a sub-directory for each feature, with JBehave stories in these sub-directories.

Inside each capability directory, a text file called narrative.txt describes the feature. The contents of this file are free text, with the first line serving as a title in the reports. An example is shown here:

Learn the meaning of a word
In order to learn the meaning of a word that I don't know
As an online reader
I want to be able to find out the meaning of the word

Acceptance criteria in JBehave take the form of simple text files with the ".story" suffix. Each ".story" file contains the acceptance criteria for one feature or story, along with an optional narrative section that describes the feature or story in question. The examples above are all written in JBehave notation: you will find them in the src/test/resources/stories directory of the sample project. A simple example is shown here:

Narrative:
In order to understand what I am reading about
As a reader
I want to be able to look up definitions of words
 
Scenario: Looking up the definition of a simple word
Given the user does not know the meaning of the word 'banana'
When the user looks up the definition of the word 'banana'
Then they should obtain a definition containing the words 'An elongated curved fruit'

Once we have a set of ".story" files, we can automate them with JBehave. Thucydides provides a convenient test harness class, called ThucydidesJUnitStories, that you can extend to run all of the JBehave stories in in the src/test/resources/stories directory. Just create a class in your project that extends this class, like the following:

import net.thucydides.jbehave.ThucydidesJUnitStories;

public class AcceptanceTestSuite extends ThucydidesJUnitStories {}


Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap