martes, diciembre 04, 2012

Writing Acceptance Tests for Openshift + MongoDb Applications



Acceptance testing are used to determine if the requirements of a specification are met. It should be run in an environment as similar as possible of the production one. So if your application is deployed into Openshift you will require a parallel account to the one used in production for running the tests. In this post we are going to write an acceptance test for an application deployed into Openshift which uses MongoDb as database backend.

The application deployed is a very very simple library which returns all the books available for lending. This application uses MongoDb for storing all information related to books.

So let's start describing the goal, feature, user story and acceptance criteria for previous application.

Goal: Expanding lecture to most people.
Feature: Display available books.
User Story: Browse Catalog -> In order to find books I would like to borrow, As a User, I want to be able to browse through all books.
Acceptance Criteria: Should see all available books.

Scenario:
Given I want to borrow a book
When I am at catalog page
Then I should see available books information: The Lord Of The Jars - 1299 - LOTRCoverUrl , The Hobbit - 293 - HobbitCoverUrl

Notice that this is a very simple application, so the acceptance criteria is simple too.

For this example, we need two test frameworks, the first one for writing and running acceptance tests, and the other one for managing the NoSQL backend. In this post we are going to use Thucydides for ATDD and NoSQLUnit for dealing with MongoDb.

The application is already deployed in Openshift, and you can take a look at https://books-lordofthejars.rhcloud.com/GetAllBooks



Thucydides is a tool designed to make writing automated acceptance and regression tests easier. 

Thucydides uses WebDriver API to access HTML page elements. But also helps you to organise your tests and user stories by using a concrete programming model, create reports of executed tests, and finally it also measures functional cover. 

To write acceptance tests with Thucydides next steps should be followed. 
  • First of all choose a user story of one of your features. 
  • Then implement the PageObject class. PageObject is a pattern which models web application's user interface elements as objects, so tests can interact with them programmatically.  Note that in this case we are coding "how" we are accessing to html page.
  • Next step is implementing steps library. This class will contain all steps that are required to execute an action. For example creating a new book requires to open addnewbook page, insert new data, and click to submit button. In this case we are coding "what" we need to implement the acceptance criteria.
  • And finally coding the chosen user story following defined Acceptance Criteria and using previous step classes.








NoSQLUnit is a JUnit extension that aims us to manage lifecycle of required NoSQL engine, help us to maintain database into known state and standarize the way we write tests for NoSQL applications. NoSQLUnit is composed by two groups of JUnit rules,  and two annotations. In current case, we don't need to manage lifecycle of NoSQL engine, because it is managed by external entity (Openshift).

So let's getting down on work:

First thing we are going to do is create a feature class which contains no test code; it is used as a way of representing the structure of requirements.

Note that each implemented feature should be contained within a class annotated with @Feature annotation. Every method of featured class represents a user story.

Next step is creating the PageObject class. Remember that PageObject pattern models web application's user interface as object. So let's see the html file to inspect what elements must be mapped.

The most important thing here is that table tag has an id named listBooks which will be used in PageObject class to get a reference to its parameters and data. Let's write the page object:

Using @DefaultUrl we are setting which URL is being mapped, with @FindBy we map the web element with id listBooks, and finally getBooksTable() method which returns the content of generated html table.

The next thing to do is implementing the steps class; in this simple case we only need two steps, the first one that opens the GetAllBooks page, and the other one which asserts that table contains the expected elements.

And finally class for validating the acceptance criteria:

There are some things that should be considered in previous class:
  • @Story should receive a class defined with @Feature annotation, so Thucydides can create correctly the report.
  • We use MongoDbRule to establish a connection to remote MongoDb instance. Note that we can use localhost address because of port forwarding Openshift capability so although localhost is used, we are really managing remote MongoDb instance.
  • Using @Steps Thucydides will create an instance of previous step library.
  • And finally @UsingDataSet annotation to populate data into MongoDb database before running the test.


Note that NoSQLUnit maintains the database into known state by cleaning database before each test execution and populating it with known data defined into a json file.

Also keep in mind that this example is very simple so only and small subset of capabilities of Thucydides and NoSQLUnit has been shown. Keep watching both sites: http://thucydides.info and https://github.com/lordofthejars/nosql-unit

We keep learning,
Alex.
Love Is A Burning Thing, And It Makes A Fiery Ring, Bound By Wild Desire, I Fell Into A Ring Of Fire (Ring of Fire - Johnny Cash)

3 comentarios:

Libin Huang dijo...

20160509libinralph lauren outlet
pandora outlet
tiffany outlet
nike huarache
ralph lauren polo
asics
camisetas futbol baratas
basketball shoes,basketball sneakers,lebron james shoes,sports shoes,kobe bryant shoes,kobe sneakers,nike basketball shoes,running shoes,mens sport shoes,nike shoes
cheap nfl jersey
fitflops clearance
timberland boots
michael kors outlet
louis vuitton pas cher
rolex watches for sale
tory burch outlet
adidas wings
coach outlet
michael kors uk
juicy couture outlet
fitflops uk
ralph lauren polo shirts
longchamp solde
tory burch outlet
cazal outlet
toms shoes
ralph lauren outlet
true religion outlet
cazal sunglasses
swarovski outlet
longchamp handbags
michael kors outlet sale
oakley sunglasses
cheap football shirts
longchamp pas cher
adidas trainers

chenlina dijo...

chenlina20160716
michael kors handbags
louis vuitton outlet stores
coach outlet
coach outlet
ghd hair straighteners
louis vuitton outlet
adidas nmd
toms shoes
true religion outlet
ray ban sunglasses discount
oakley sunglasses
louis vuitton bags
michael kors outlet
louis vuitton
hermes handbags
nike trainers men
ray ban sunglasses
nike free runs
pandora jewelry
cheap nfl jerseys
cheap air jordans
gucci handbags
louis vuitton handbags
burberry bags
louboutin shoes
michael kors outlet online sale
michael kors purses
adidas superstar
oakley sunglasses
beats by dr dre
gucci belts
coach factory outlet online
cheap oakley sunglasses
michael kors outlet
louis vuitton handbags
coach factory outlet
oakley canada
toms wedges
louis vuitton
coach outlet
as

Gege Dai dijo...

asics,asics israel,asics shoes,asics running shoes,asics israel,asics gel,asics running,asics gel nimbus,asics gel kayano
nike air huarache
ferragamo shoes
michael kors outlet online
ray ban sunglasses
oakley sunglasses
replica watches
ray-ban sunglasses
air max 90
michael kors uk outlet
coach outlet store
hollister clothing store
fitflops sale clearance
michael kors outlet online
ray ban sunglasses
michael kors clearance
ferragamo outlet
longchamp outlet
michael kors outlet
pandora outlet
cheap replica watches
pandora outlet
timberland boots
burberry sunglasses
michael kors factory outlet
mulberry outlet
michael kors outlet
reebok outlet store
true religion outlet
nike air max 90
michael kors outlet
gucci sunglasses uk
true religion outlet
celine outlet online
prada sunglasses
czq20160722

Donate If You Can and Find Post Useful