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 - Keep love alive

800 views

Published on

BDD using jbehave and serenityBDD

Published in: Software
  • Login to see the comments

BDD - Keep love alive

  1. 1. Behaviour Driven Development (BDD) (AKA Keep BDD Love Alive) @rorypreddy
  2. 2. Agenda • Intro • TDD and BDD • Tools –JBehave –Serenity • How to Keep BDD Love Alive
  3. 3. A “little” bit about Rory • Technology Evangelist at BBD – www.bbd.co.za • Organizer for Jozi-JUG and Joburg AWS User Forum (AWS-Jozi) • Not related to Tyrion Lannister • Don’t do kids parties
  4. 4. SENDER Step 1: Make an appointment “I would like to Dialogue about something. Is now OK?” Step 2: The Send “I feel…”, “I tell myself…”, “My desire is…” Step 3: The Summary “You got it all” RECEIVER Step 1: Agree to the appointment “I’m available now” Step 2: The Mirror and the Check I heard you say…, You said… Step 3: The Summary “Am I getting you? Did I get all of that?”
  5. 5. Agenda • Intro • TDD and BDD • Tools –JBehave –Serenity • How to Keep BDD Love Alive
  6. 6. BDD is about having conversations BDD should make it easy to create software A scenario is an idea, not a promise
  7. 7. So BDD is… • An evolution of Test Driven Development • Created by Dan North in 2003: “Programmers wanted to know where to start, what to test and what not to test, how much to test in one go, what to call their tests, and how to understand why a test fails.”
  8. 8. BDD Given- Set of preconditions Then-Some testable outcome When-When a event occurs Uses Given-Then-When (Gherkin)
  9. 9. Lets define ATDD and TDD ATDD FitNesse Spectacular Concordian Serenity BDD SpecFlow Cucumber JBehave NBehave Behat TDD JUnit NUnit TestNG MSTest
  10. 10. Test Driven Development (TDD) Kent Beck defines: • Never write a single line of code unless you have a failing automated test. • Eliminate duplication. • Red (Automated test fail) • Green (test pass) • Refactor (Clean the code) RED GREENREFACTOR TDD
  11. 11. BDD Write an acceptance test Run the acceptance test Create software Acceptance Test Driven Development = BDD combined with TDD Create software Make the test pass REFACTOR TDD Write a failing test + Verification
  12. 12. Agenda • Intro • TDD and BDD • Tools –JBehave –Serenity • How to Keep BDD Love Alive
  13. 13. JBehave • Created by Dan North in 2003 • Original BDD framework • Great Tooling and IDE plugins • Uses Given/Then/When in plain text • Decision tables –we know you love excel
  14. 14. Write a Story Given a shopping cart When one item is added Then the cart should have 1 items in it …
  15. 15. Map Steps to Code @Given("a shopping cart") public void aCart() { cart = new ShoppingCart(); } @When("one item is added") public void addAnItem() { cart.getItems().add(new Item("Juice", Item.SHELF.TOP)); } @Then("the cart should have $numberOfItems items in it") public void checkItemsSaved(int numberOfItems) { assertEquals(numberOfItems, cart.getItems().size()); }
  16. 16. Run Stories
  17. 17. Demo Given a shopping cart When there is help for a hard to reach item Then help should give me that item Examples: |itemName|shelf|help |Eggs|BOTTOM|true |tabasco|MIDDLE|true |Juice|TOP|false
  18. 18. Tools ATDD FitNesse Spectacular Concordian Serenity BDD SpecFlow Cucumber JBehave NBehave Behat TDD JUnit NUnit TestNG MSTest
  19. 19. Self- documenting SeleniumJBehave with JUnit Layered BDD Serenity (Thucydides) Goals Tasks Interactions
  20. 20. Feature: Rory thinks Add new todos needs to be able to jot down actions he needs to do as he of them Scenario: Record a new todo action to buy for future use Given Rory needs some milk When Rory adds the todo action 'Bu y som e milk' Then 'Buy some milk' should be recorded in his todo list A goal A task @Steps ATodoUser rory; @When(“^(?:.*) (?:adds|has added) the todo action '(.*)'$") public void i_add_the_todo_action(String actionName) { rory.adds_an_action_called(actionName); } The task definition TodoPage onTheTodoHomePage ; An interaction @Step public void adds_an_action_called(String actionName) { onTheTodoHomePage.addAnActionCalled(actionName); } The Serenity layered architecture
  21. 21. Feature: Add new todos I need to be able to jot down actions I need to do as fast as I think of them Scenario: Given I Record a new todo action for future use need to buy some milk When I add the todo action 'Buy some milk' Then 'Buy some milk' should be recorded in my todo list Serenity documentation
  22. 22. Demo Time! Given I need to <definition1> When I add the todo action "<action1>" Then "<action1>" should be recorded in my todo list Examples: |definition1|action1 |buy some milk|Buy some milk |buy some sugar|Buy some sugar
  23. 23. Highly readable style Encourages reuse and maintainable code Small, reusable interaction components User-centric Why is Serenity Different? -The Journey Pattern
  24. 24. Meet Rory Journey Pattern -An Actor
  25. 25. Actors have goals Given Rory needs to buy some milk When Rory adds the todo action 'Buy some milk' Then 'Buy some milk' should be recorded in his todo list I’d like to be able to recall all the things I need to do Journey Pattern
  26. 26. Actors have abilities I can browse the web with my browser Journey Pattern Actor rory = Actor.named(“Rory"); @Managed WebDriver hisBrowser; … rory.can(BrowseTheWeb.with(hisBrowser));
  27. 27. I’ll add ‘Buy some milk’ to my todo list Actors perform tasks Journey Pattern @Steps AddItem addATodoItem; … rory.attemptsTo(addATodoItem.called("Buy some milk"));
  28. 28. Actors may interact with the system to perform these tasks Type ‘Buy the milk’ Press ‘ENTER’ Journey Pattern
  29. 29. Journey Pattern Goals Elements ScreenActor Tasks ActionsAbilities have About the state of On a Interact with enable Made up of Performs has
  30. 30. PageObject Pattern DesiredCapabilites desiredCapabilities= new DesiredCapabilites(); WebDriver driver = new PhantomJSDriver(desiredCapabilities()); driver.get(baseUrl+"owners/find.html"); FindOwnersPage findOwners = PageFactory.initElements(driver, FindOwnersPage.class); OwnersPage owners = findOwners.findWith(EMPTY_SEARCH_TERMS); assertThat(owners.numberOfOwners(), is(10); Journey Pattern Actor theReceptionist = new Actor().with(WebBrowsing.ability(); theReceptionist.attemptsTo( Go.to(findOwnersScreeen.url), Search.forOwnersWith(EMPTY_SEARCH_TERMS), Count.theNumberOfOwners() ); assertThat( theReceptionist.sawThatThe(numberOfOwners()), was(theExpectedNumberOfOwners) );
  31. 31. Jenkins (Continuous Integration)
  32. 32. JIRA
  33. 33. Agenda • Intro • TDD and BDD • Tools –JBehave –Serenity • How to Keep BDD Alive
  34. 34. We have large BDD suites written in a Cucumber Clone • They spend much of their life red Customers don’t engage with our BDD suites • And yet we spend a lot of time maintaining them Our BDD suites are slow to run and increase the cost of the “check-in dance” • Developers start ignoring red results • And we have to down tools to fix them Developers don’t want to write them • Because they can’t see the value return on their effort • They just want to build software BDD Counselling
  35. 35. How to Keep BDD Alive • Don’t Skip the conversation • Involve the whole team • Use Journeys not Events • Accept you’ll still miss things
  36. 36. How to Keep BDD Love Alive • Work on it - don’t rely on “magic”. • “Its 50% your responsibility” • Avoid –Criticism –Contempt –Defensiveness –Stonewalling
  37. 37. What did We Learn? • What is BDD • Tools –JBehave –Serenity • How to Keep BDD Love Alive • Lookout! –Shameless User Group Plug coming up…
  38. 38.  AWS-JOZI - www.meetup.com/AWS-JOZI  New AWS centric User group  Top notch venues  Jozi-JUG - www.meetup.com/Jozi-JUG  2000 members  Sessions of +200 attendees  Conferences and monthly meetups  Venues rotate around Johannesburg & Self Social Mentorship Community Culture Experience Relevance Education Career
  39. 39. Questions @rorypreddy • https://github.com/roryp/jbehave-tutorial • https://github.com/roryp/jbehave-webtest-todomvc

×