bdd using jbehave

12
jBehave A Java library for Behavior Driven Development By Ajit Skanda Kumaraswamy ([email protected] ) Backbase BV Amsterdam 29th May 2012 Tuesday, May 29, 12

Upload: ajit-skanda-kumaraswamy

Post on 19-Jun-2015

959 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: BDD using JBehave

jBehaveA Java library for Behavior Driven Development

ByAjit Skanda Kumaraswamy

([email protected])

Backbase BV Amsterdam29th May 2012

Tuesday, May 29, 12

Page 2: BDD using JBehave

In today’s presentation...

n What is Acceptance Testing?

n What is Behavior Driven Development?

n jBehave and its features

n An example jBehave test

n Salient features of jBehave

Tuesday, May 29, 12

Page 3: BDD using JBehave

Acceptance Testing

n What is Acceptance testing?

n Why is it important?

n Who writes Acceptance tests? When?

Tuesday, May 29, 12

Page 4: BDD using JBehave

Behavior Driven Development

n What is BDD?

n How is it different from TDD?

n How do we benefit from it?

n Acceptance testing and BDD

n BDD using jBehave

Tuesday, May 29, 12

Page 5: BDD using JBehave

Introduction to jBehaven Basic Concepts

n Story

n Steps Class

n Configuration

n Advanced topics

n jBehave with Spring and Maven

n Example in jBehave

Tuesday, May 29, 12

Page 6: BDD using JBehave

jBehave basics 1 - story

Example Story

Scenario:  trader is not alerted below threshold Given a stock of symbol STK1 and a threshold of 10.0When the stock is traded at 5.0Then the alert status should be OFF Scenario:  trader is alerted above threshold Given a stock of symbol STK1 and a threshold of 10.0When the stock is traded at 11.0Then the alert status should be ON

n A textual representation of the business feature to be developed

n A collection of scenarios for the given feature

n Can be located on the classpath or on a url

n Can be written in plain-text, ODT format and other formats like html

Tuesday, May 29, 12

Page 7: BDD using JBehave

jBehave basics 2 - Steps Class

Example Steps POJO class

public class TraderSteps {    private Stock stock;     @Given("a stock of symbol $symbol and a threshold of $threshold")    public void aStock(String symbol, double threshold) {        stock = new Stock(symbol, threshold);    }     @When("the stock is traded at $price") @Alias("the stock is sold at $price")    public void theStockIsTradedAt(double price) {        stock.tradeAt(price);    }     @Then("the alert status should be $status")    public void theAlertStatusShouldBe(String status) {        ensureThat(stock.getStatus().name(), equalTo(status));    } }

n Mapping textual scenario steps to Java methods

n Each annotation corresponds to one step of a given scenario

n A simple regex pattern holds the value

n After/Before - Scenario, Story and Stories

n Spring, Configuration based

Tuesday, May 29, 12

Page 8: BDD using JBehave

jBehave basics 3 - Configuration

n Different ways of running:

n Embedded vs storyPaths

n Local vs Remote

n Embeddable - Combining Configuration and CandidateSteps

n Configuration:

n Story parsing and loading

n StoryReporterBuilder and ViewGenerator

n Multiple stories using JUnitStories

n WebRunner Configuration (Ex. Selenium)

Tuesday, May 29, 12

Page 9: BDD using JBehave

jBehave advanced - Spring and Maven

n Excellent support for Spring framework

n SpringAnnotatedEmbedderRunner

n @UsingSpring

n InjectableStepsFactory for Steps beans

n jBehave Maven plugin and its configuration

n unpack, mapping, running, reporting

n A concurrent Jenkins plugin

Tuesday, May 29, 12

Page 10: BDD using JBehave

jBehave - Example

n An example from jBehave tutorials - Selenium tests to run stories on etsy.com

Tuesday, May 29, 12

Page 11: BDD using JBehave

Salient Features of jBehaven Very powerful and flexible

n Separation of text stories from code and config

n Extensive support for different frameworks and environments

n Good documentation/example and online forums

n Comprehensive reporting options

n Steep learning curve!

Tuesday, May 29, 12

Page 12: BDD using JBehave

Thank you

Questions?

Tuesday, May 29, 12