how and why to love cucumber by dana scheider. is this your programming experience?
TRANSCRIPT
WHY AND HOW TO LOVE CUCUMBER
HOW AND WHY TO LOVE CUCUMBERBy Dana Scheider
1Is This Your Programming Experience?
The RSpec BookThe whole first part of The RSpec Book is about Cucumber.
Behavior-driven development is important and Cucumber is an excellent tool for the job.Thesis
4Why Im HereSoftware testing is fun!Cucumber is really fun!Many people dont grok Cucumbers use casesIm tired of the way you roll your eyes at me when I tell you I use and contribute to Cucumber
OutlineWhat is (and isnt) Cucumber?Cucumber and behavior-driven developmentWhy some developers dont like CucumberHow to love Cucumber
What Cucumber IsIllustrationsWhat Cucumber IsntWhat Is Cucumber?
What Is Cucumber?Acceptance testing toolComposed of features and scenarios written in Gherkin DSL, and step definitions written in Cucumber step definition DSLUnderstandable to nontechnical team membersCreates documentation as you write your tests
Every Cucumber feature has one or more scenarios, which highlight different use cases, types of input, application states, etc. State is maintained within each scenario, and individual steps, beginning with Given, When, Then, and And keywords, run in the context created by previous steps in the same scenario.Gherkin Example
Each step has a step definition that either (A) defines changes in the environment, (B) triggers UI events, or (C) sets an expectation using the RSpec expectations API. If the change in the environment/context cannot be made, the UI event cannot be effected, or the expectation is not met, any scenario containing that step fails.Cucumber Step Definition Example
11What Isnt Cucumber?Unit testing toolReplacement for unit testingLow-levelStateless
What Is BDD?Why BDD?What is Integration Testing?Example with Cucumber & RspecCucumber and BDD
What Is BDD?Focused on API the user usesCombines unit and integration/acceptance testingTests are written firstMinimal planning up front
The BDD/TDD Cycle
Why BDD?You need to know what your software doesUsers need to know your software works as advertisedTesting enables you to take more risks in the development processReduces technical debtIf the code isnt important enough to test, is it important enough to deploy or deliver to clients?
What Is Acceptance Testing?High levelNot concerned with details of implementationMimics how actual users use the softwareCovers as much of the API as possible
Relationship to Unit Testing Covers the program as a wholeTests from the users perspectiveNot concerned with implementationCovers specific parts of the programTests things the user cant seeConcerned with how individual parts of the code work & interactAcceptance TestingUnit Testing
Each system needs multiple integration/acceptance tests covering user-facing functionality. As that functionality is developed, unit tests are added to test implementation-specific elements that are needed to support the API.Software Suite Structure
Unit testing and integration testing have aboth/and, not either/or, relationshipRelationship to Unit Testing
20Cucumber and BDDUse Cucumber for acceptance/integration tests onlyCucumber features determine what unit tests are neededIf unit tests pass, Cucumber features should pass, tooIf unit tests fail, Cucumber features should fail, tooCucumber provides direction for behavior-driven workflows
Things about testing/TDD/BDDThings about CucumberThings about developersWhy Some Devs Dont Like It
Things about TDD/BDDTakes more time before you start codingMakes you look at software from users POVCan be daunting to break a complex problem down into the smallest possible partFeels unnecessary, especially at first
Things about CucumberUses regular expressions*Natural language can seem needlessly clunkyTests can take a longer time than with other frameworksCan be hard to organize feature and step-definition files
* You can use strings instead if you REALLY hate the regular expressions
Things about DevelopersAlready using testing tools that work better for themTrying to use Cucumber for unit testsNot taking advantage of the tools in Cucumbers rich ecosystemUnable to articulate in plain, natural, language what their software doesReluctant to bring nontechnical team members and stakeholders into the fold
Conceptualizing CucumberContextualizing CucumberAdopting Effective WorkflowsOrganizing Your FeaturesTaking Advantage of the EcosystemHow to Love Cucumber
Conceptualizing CucumberCucumber is for integration testingUse Cucumber to write documentation and ensure your software adheres to itUse your imagination to see your software from the perspective of your eventual userExplain your use cases and break the explanations down into Cucumber steps
Conceptualizing Cucumber
Contextualizing CucumberDont stop unit testing!Let Cucumber features guide development processTake advantage of Cucumbers ability to maintain state between stepsRemember Cucumber is about the user, not the devUse Cucumbers natural-language style to reach consensus with nontechnical stakeholders about specs and deliverables
Adopting Effective WorkflowsWrite Cucumber features before writing unit testsDiscuss Cucumber features with nontechnical team members or stakeholders before writing unit testsIf unit tests pass and features fail, write more unit testsIf unit tests fail and features pass, consider refactoring to remove redundant or unneeded codeRefactor liberallyUse continuous integration/delivery!
SummaryTDD/BDD is cool!Cucumbers pretty cool too!Questions?Conclusion
What TDD & Cucumber Can Bring to Your ProjectsBetter code qualityLess codeLess technical debtBuilt-in documentation known to be accurateKnowledge about what your app brings to users, in language users can understandEasy communication with nontechnical peopleFun and happiness!
E-mail: [email protected]: danascheiderTwitter: @danascheiderDana Scheider