Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

BDD using JBehave

2,536 views

Published on

  • Be the first to comment

BDD using JBehave

  1. 1. jBehave A Java library for Behavior Driven Development By Ajit Skanda Kumaraswamy (ajit@backbase.com) Backbase BV Amsterdam 29th May 2012Tuesday, May 29, 12
  2. 2. 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 jBehaveTuesday, May 29, 12
  3. 3. Acceptance Testing n What is Acceptance testing? n Why is it important? n Who writes Acceptance tests? When?Tuesday, May 29, 12
  4. 4. 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 jBehaveTuesday, May 29, 12
  5. 5. Introduction to jBehave n Basic Concepts n Story n Steps Class n Configuration n Advanced topics n jBehave with Spring and Maven n Example in jBehaveTuesday, May 29, 12
  6. 6. jBehave basics 1 - story n A textual representation of the Example Story business feature to be developed Scenario:  trader is not alerted below threshold   n A collection of scenarios for the Given a stock of symbol STK1 and a given feature threshold of 10.0 When the stock is traded at 5.0 Then the alert status should be OFF n Can be located on the classpath   or on a url Scenario:  trader is alerted above threshold   n Can be written in plain-text, Given a stock of symbol STK1 and a threshold of 10.0 ODT format and other formats When the stock is traded at 11.0 like html Then the alert status should be ONTuesday, May 29, 12
  7. 7. jBehave basics 2 - Steps Class n Mapping textual scenario steps Example Steps POJO class to Java methods public class TraderSteps {     private Stock stock; n Each annotation corresponds to       @Given("a stock of symbol $symbol and a threshold of one step of a given scenario $threshold")     public void aStock(String symbol, double threshold) {         stock = new Stock(symbol, threshold);     }   n A simple regex pattern holds     @When("the stock is traded at $price") @Alias("the stock is sold at $price") the value     public void theStockIsTradedAt(double price) {         stock.tradeAt(price);     }   n After/Before - Scenario, Story     @Then("the alert status should be $status")     public void theAlertStatusShouldBe(String status) { and Stories         ensureThat(stock.getStatus().name(), equalTo(status));     }   } n Spring, Configuration basedTuesday, May 29, 12
  8. 8. 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
  9. 9. 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 pluginTuesday, May 29, 12
  10. 10. jBehave - Example n An example from jBehave tutorials - Selenium tests to run stories on etsy.comTuesday, May 29, 12
  11. 11. Salient Features of jBehave n 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
  12. 12. Thank you Questions?Tuesday, May 29, 12

×