class: center, middle # Gherkin, Cucumber and Behavior Driven Development --- # A Common Software Development Problem ### We don't understand each other -- ### It takes us a while to figure that out -- ### So we waste a bunch of time doing the wrong thing --- # Gherkin ### Gherkin is a Business Readable, Domain Specific Language created especially for behavior descriptions. -- ### It supports the definition of features and the supporting interaction scenarios. -- ### A feature is a business **Story** -- ### A scenario is a business **Use Case** --- # Gherkin Structure ``` Feature: Some terse yet descriptive text of what is desired In order to realize a named business value As an explicit system actor I want to gain some beneficial outcome which furthers the goal Scenario: Some determinable business situation Given some precondition And some other precondition When some action by the actor And some other action And yet another action Then some testable outcome is achieved And something else we can check happens too Scenario: A different situation ... ``` --- # Gherkin Usage ### Ideally, business users would write features in Gherkin ### Realistically, Gherkin is a middle ground where business users and technologists can seek agreement ### Useful in and of itself, if only to create clarity Gherkin supports over 60 spoken languages. -- ### Which brings us to Cucumber --- # Cucumber ### Cucumber is a software tool to automate acceptance tests written in a **Behavior-Driven Development** style. Available for * Ruby * Java * JavaScript * Lua * PHP * C++ * ... --- # Tell me what to do When cucumber encounters a feature file without the corresponding step definitions, then it will tell you what it needs ([Jersey, Gson and DataTables](https://github.com/ideoplex/jersey-gson/commit/5695d15c0b070432a872ab814eb9a943dac62bb2) on github). ``` $ mvn test -Dskip=client,browser -q 2 Scenarios (2 undefined) 8 Steps (8 undefined) 0m0.000s You can implement missing steps with the snippets below: @Given("^prospective user with email \"([^\"]*)\" pre-exists$") public void prospective_user_with_email_pre_exists(String arg1) throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); } ... Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.996 sec - in TestSuite Results : Tests run: 5, Failures: 0, Errors: 0, Skipped: 0 ``` --- # Run it for me ``` $ mvn test -Dskip=client,browser -q ------------------------------------------------------- T E S T S ------------------------------------------------------- Running TestSuite Configuring TestNG with: TestNG652Configurator 2 Scenarios (1 pending, 1 passed) 8 Steps (1 pending, 7 passed) 0m0.377s cucumber.api.PendingException: TODO: implement me at com.ideoplex.tutorial.UserManagementStepdefs.email_is_registered(UserManagementStepdefs.java:40) at ✽.Then email "user@example.com" is registered(com/ideoplex/tutorial/userManagement.feature:7) Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.367 sec - in TestSuite Results : Tests run: 5, Failures: 0, Errors: 0, Skipped: 0 ``` --- # Tell me how I did **See Example Project** --- # Behavior Driven Development BDD is an outgrowth of Test-Driven Development, with a focus on balancing business interests and technical insight. Traditionally, TDD occurs at a much finer level - directed at the developers themselves. BDD is meant to happen at a higher level, to assist in the establishment of business priorities and high level system capabilities. -- TDD addresses **does my code satisfy my requirements** BDD addresses **does my code provide business value**