Learning Behavior-driven Development with JavaScript
eBook - ePub

Learning Behavior-driven Development with JavaScript

Enrique Amodeo

Buch teilen
  1. 392 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Learning Behavior-driven Development with JavaScript

Enrique Amodeo

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Learning Behavior-driven Development with JavaScript als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Learning Behavior-driven Development with JavaScript von Enrique Amodeo im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Web Services & APIs. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2015
ISBN
9781784392642

Learning Behavior-driven Development with JavaScript


Table of Contents

Learning Behavior-driven Development with JavaScript
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Welcome to BDD
The test-first approach
The test-first cycle
Write a failing test
Make the test pass
Clean the code
Repeat!
Consequences of the test-first cycle
BDD versus TDD
Exploring unit testing
The structure of a test
Test doubles
What is a good test?
Summary
2. Automating Tests with Mocha, Chai, and Sinon
Node and NPM as development platforms
Installing Node and NPM
Configuring your project with NPM
Introducing Mocha
Useful options in Mocha
Our first test-first cycle
More expressive assertions with Chai
Working with the "should" interface
Red/Green/Refactor
Parameterized tests
Organizing your setup
Defining test scenarios
Test doubles with Sinon
Is it traditional TDD or BDD?
Welcome Sinon!
Integrating Sinon and Chai
Summary
3. Writing BDD Features
Introducing myCafé
Writing features
Displaying a customer's order
Tips for writing features
Starting to code the scenarios
Testing asynchronous features
Testing a callback-based API
Testing a promise-based API
Interlude – promises 101
Mocha and promises
Chai-as-Promised
Test doubles with promises
Organizing our test code
The storage object pattern
The example factory pattern
Finishing the scenario
Parameterized scenarios
Finishing our feature
Summary
4. Cucumber.js and Gherkin
Getting started with Gherkin and Cucumber.js
Preparing your project
Writing your first scenario in Gherkin
Executing Gherkin
The World object pattern
Better step handlers
Better reporting
Writing advanced scenarios
Gherkin example tables
Consolidating steps
Advanced setup
Gherkin-driven example factory
Implicit versus explicit setup
The Background section
Parameterized scenarios
Finishing the feature
Useful Cucumber.js features
Tagging features and scenarios
Hooks
The before hook
The after hook
The around hook
Non-English Gherkin
Cucumber.js or Mocha?
Summary
5. Testing a REST Web API
The approach
A strategy to test web APIs
Mocha or Cucumber.js?
The plan
Testing the GET order feature
Exploring our feature a bit
Starting, stopping, and setting up our server
Testing whether the API responds with 200 Ok
Should we use a realistic order object?
Implementing the test
Testing our HAL resource for orders
The contract with the business layer
Finishing the scenario
Testing slave resources
The order actions
Testing embedded resources
Extracting cross-cutting scenarios
Homework!
Summary
6. Testing a UI Using WebDriverJS
Our strategy for UI testing
Choosing the right tests for the UI
The testing architecture
WebDriverJS
Finding and interacting with elements
Complex UI interaction
Injecting scripts
Command control flows
Taking screenshots
Working with several tabs and frames
Testing a rich Internet application
The setup
The test HTML page
Serving the HTML page and scripts
Using browserify to pack our code
Creating a WebDriver session
Testing whether our view updates the HTML
Testing whether our view reacts with the user
What about our UI control logic?
Summary
7. The Page Object Pattern
Introducing the Page Object pattern
Best practices for page objects
A page object for a rich UI
Building a page object that reads the DOM
Building a page object that interacts with the DOM
Testing the navigation
Summary
8. Testing in Several Browsers with Protractor and WebDriver
Testing in several browsers with WebDriver
Testing with PhantomJS
Running in several browsers
The Selenium Server
Welcome Protractor!
Running the tests in parallel
Other useful configuration options
Using the Protractor API
Summary
9. Testing Against External Systems
Writing good test doubles
Testing against external systems
Testing against a database
Accessing the DB directly
Treating the DAO as a collection
Testing against a third-party system
The record-and-replay testing pattern
Summary
10. Final Thoughts
TDD versus BDD
A roadmap to BDD
BDD versus integration testing
BDD is for testing problem domains
Concluding the book
Next steps?
Summary
Index

Learning Behavior-driven Development with JavaScript

Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: February 2015
Production reference: 1130215
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78439-264-2
www.packtpub.com

Credits

Author
Enrique Amodeo
Reviewers
Domenico Luciani
Mihir Mone
Takeharu Oshida
Juri Strumpflohner
Commissioning Editor
Pramila Balan
Acquisition Editor
Richard Brookes-Bland
Content Development Editors
Sriram Neelakantan
Sharvari Tawde
Technical Editor
Indrajit A. Das
Copy Editors
Karuna Narayanan
Laxmi Subramanian
Project Coordinator
Judie Jose
Proofreaders
Stephen Copestake
Maria Gould
Paul Hindle
Indexer
Priya Sane
Graphics
Sheetal Aute
Production Coordinator
Nitesh Thakur
Cover Work
Nitesh Thakur

About the Author

Enrique Amodeo is an experienced software engineer currently working and living in Berlin. He is a very eclectic professional with very different interests and more than 15 years of experience. Some of his areas of expertise are JS, BDD/TDD, REST, NoSQL, object-oriented programming, and functional programming.
As an agile practitioner, he uses BDD and emergent design in his everyday work and tries to travel light. Experienced in both frontend and server-side development, he has worked with several technical stacks, including Java/JEE, but since 2005, he prefers to focus on JS and HTML5. He is now very happy to be able to apply his JS knowledge to the server-side development, thanks to projects such as Node.js.
He also has written a book in Spanish on designing web APIs, following the REST and hypermedia approach (https://leanpub.com/introduccion_apis_rest).

About the Reviewers

Domenico Luciani is a software and web developer and compulsive coder. He is curious and is addicted to coffee. He is a computer science student and a passionate pentester and computer-vision fanatic.
Having fallen in love with his job, he lives in Italy; currently, he is working for many companies in his country as a software/web developer. You can find more information on him at http://dlion.it/.
Mihir Mone is a postgraduate from Monash University, Australia. Although he did his post graduation in network computing, these days, he mainly does ...

Inhaltsverzeichnis