ebook img

The Cucumber Book: Behaviour-Driven Development for Testers and Developers PDF

328 Pages·2012·6.926 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview The Cucumber Book: Behaviour-Driven Development for Testers and Developers

www.it-ebooks.info What Readers Are Saying About The Cucumber Book Few tools have managed to bridge the developer-customer divide as well as Cucumber has. Cucumber is not a tool for testing applications. Cucumber is a philosophy for communicating requirements. This book brings that philosophy to life. ➤ Robert C. Martin (Uncle Bob) I devoured the Cucumber book on a train ride from Grenoble to Brussels a few days after watching Matt’s presentation “BDD As It’s Meant to Be Done.” These two resources helped me understand in just a few hours how to avoid dozens of common mistakes writing scenarios in the Cucumber style. It’s as though I received an injection of perhaps two years of experience writing scenarios poorly so that I didn’t have to go through it all myself. What a gift. I recommend this book to everyone working with Cucumber. ➤ J. B. Rainsberger Author, JUnit Recipes www.it-ebooks.info Teams can use Cucumber to get a better understanding of what software to build for their customers. In this book, Aslak and Matt do a brilliant job explaining how you get started with Cucumber with plenty of easy-to-follow examples. ➤ Rachel Davies Author, Agile Coaching To those of you wondering how to use Cucumber effectively, The Cucumber Book is the answer. Not content to write just a testing book, Aslak and Matt have packed it with practical insights on many aspects of software development. Studying this book will make you a better software developer. ➤ Pat Maddox, B.D.D.M.F. RSpec Core team This is a much-needed book, providing not only an expanded description of how to use Cucumber but an opinionated one to suggest how to use it for the best effect. Reading this book is like having Aslak and Matt sitting next to you, patiently helping you through your first project with Cucumber. Not only will you learn effective use of Cucumber, but you’ll also be introduced to several other Ruby tools that can be used with Cucumber. ➤ George Dinwiddie Software development coach at iDIA Computing, LLC www.it-ebooks.info Matt and Aslak show you how Cucumber can save you from stale documentation, unclear requirements, and absentee tests. By the end of the book, your team’s programmers, testers, and product owners will be talking excitedly about the next great product you’re going to build together. ➤ Ian Dees Author, Scripted GUI Testing with Ruby This book had me at “Cucumber is designed to help build bridges between the technical and nontechnical members of a software team.” Wynne and Hellesøy understand the whole-team approach to specification by example, with diverse team members collaborating to deliver what the customer really wants. They use examples to teach us how to automate regression checks with Cucumber, use it to build a safety net to allow refactoring, and free testers to contribute their most valuable skills to the team. ➤ Lisa Crispin Author, Agile Testing: A Practical Guide for Testers (with Janet Gregory) This book is a tale of how to do effective acceptance testing, with Cucumber as the filling in the sandwich. The authors don’t just scratch the surface; they get right under the skin and show us how versatile Cucumber can be. ➤ Robert Chatley Principal, Devlogical www.it-ebooks.info Lots of great tips for Cucumber newbies and experts alike—Matt and Aslak have done a great job of explaining everything from getting started to how to get the most out of Cucumber. You’ll want to read this book cover to cover and keep it close as a reference! ➤ Gojko Adzic Author, Specification by Example and Bridging the Communication Gap The Cucumber Book is a must-read for anyone thinking about using Cucumber; it is scattered with treasures for even the most experienced Cucumber users. ➤ Antony Marcano RiverGlide www.it-ebooks.info The Cucumber Book Behaviour-Driven Development for Testers and Developers Matt Wynne Aslak Hellesøy The Pragmatic Bookshelf Dallas, Texas • Raleigh, North Carolina www.it-ebooks.info Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trade- marks of The Pragmatic Programmers, LLC. Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein. Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com. The team that produced this book includes: Jackie Carter (editor) Potomac Indexing, LLC (indexer) Kim Wimpsett (copyeditor) David J Kelly (typesetter) Janet Furlow (producer) Juliet Benda (rights) Ellie Callahan (support) Copyright © 2012 Pragmatic Programmers, LLC. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. Printed in the United States of America. ISBN-13: 978-1-934356-80-7 Printed on acid-free paper. Book version: P1.0—January 2012 www.it-ebooks.info Contents Foreword . . . . . . . . . . . . . xiii Acknowledgments . . . . . . . . . . . xv Preface . . . . . . . . . . . . . . xvii Part I — Cucumber Fundamentals 1. Why Cucumber? . . . . . . . . . . . . 3 1.1 Automated Acceptance Tests 4 1.2 Behaviour-Driven Development 4 1.3 Living Documentation 6 1.4 How Cucumber Works 7 1.5 What We Just Learned 8 2. First Taste . . . . . . . . . . . . . 11 2.1 Understanding Our Goal 11 2.2 Creating a Feature 12 2.3 Creating Step Definitions 14 2.4 Implementing Our First Step Definition 16 2.5 Running Our Program 17 2.6 Changing Formatters 18 2.7 Adding an Assertion 19 2.8 Making It Pass 20 2.9 What We Just Learned 23 3. Gherkin Basics . . . . . . . . . . . . 25 3.1 What’s Gherkin For? 25 3.2 Format and Syntax 28 3.3 Feature 29 3.4 Scenario 30 3.5 Comments 33 www.it-ebooks.info Contents • ix 3.6 Spoken languages 34 3.7 What We Just Learned 35 4. Step Definitions: From the Outside . . . . . . . 39 4.1 Steps and Step Definitions 40 4.2 Capturing Arguments 45 4.3 Multiple Captures 49 4.4 Flexibility 50 4.5 Returning Results 52 4.6 What We Just Learned 58 5. Expressive Scenarios . . . . . . . . . . 61 5.1 Background 61 5.2 Data Tables 64 5.3 Scenario Outline 70 5.4 Nesting Steps 75 5.5 Doc Strings 78 5.6 Staying Organized with Tags and Subfolders 79 5.7 What We Just Learned 82 6. When Cucumbers Go Bad . . . . . . . . . 85 6.1 Feeling the Pain 86 6.2 Working Together 89 6.3 Caring for Your Tests 97 6.4 Stop the Line and Defect Prevention 105 6.5 What We Just Learned 106 Part II — A Worked Example 7. Step Definitions: On the Inside . . . . . . . . 111 7.1 Sketching Out the Domain Model 112 7.2 Removing Duplication with Transforms 117 7.3 Adding Custom Helper Methods to the World 120 7.4 Organizing the Code 128 7.5 What We Just Learned 131 8. Support Code . . . . . . . . . . . . 133 8.1 Fixing the Bug 134 8.2 Bootstrapping the User Interface 141 8.3 Making the Switch 142 8.4 Using Hooks 147 www.it-ebooks.info Contents • x 8.5 Building the User Interface 150 8.6 What We Just Learned 154 9. Dealing with Message Queues and Asynchronous Components . . . . . . . . . . 157 9.1 Our New Asynchronous Architecture 157 9.2 How to Synchronize 158 9.3 Implementing the New Architecture 161 9.4 Fixing the Flickering Scenario 165 9.5 What We Just Learned 171 10. Databases . . . . . . . . . . . . . 173 10.1 Introducing ActiveRecord 174 10.2 Refactoring to Use a Database 175 10.3 Reading and Writing to the Database 178 10.4 Cleaning the Database with Transactions 181 10.5 Cleaning the Database with Truncation 185 10.6 What We Just Learned 186 Part III — Cucumber Applied 11. The Cucumber Command-Line Interface . . . . . 191 11.1 Cucumber’s Command-Line Options 191 11.2 Running a Subset of Scenarios 192 11.3 Changing Cucumber’s Output 194 11.4 Specifying the Location of Step Definitions 196 11.5 Managing Your Work in Progress (WIP) 197 11.6 Using Profiles 198 11.7 Running Cucumber from Rake 198 11.8 Running Cucumber in Continuous Integration 199 11.9 What We Just Learned 200 12. Testing a REST Web Service . . . . . . . . 201 12.1 In-Process Testing of Rack-Based REST APIs 202 12.2 Out-of-Process Testing of Any REST API 213 12.3 What We Just Learned 220 13. Adding Tests to a Legacy Application . . . . . . 221 13.1 Characterization Tests 222 13.2 Squashing Bugs 224 13.3 Adding New Behavior 225 www.it-ebooks.info

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.