Learning Behavior-driven Development with JavaScript
eBook - ePub

Learning Behavior-driven Development with JavaScript

Enrique Amodeo

Compartir libro
  1. 392 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Learning Behavior-driven Development with JavaScript

Enrique Amodeo

Detalles del libro
Vista previa del libro
Índice
Citas

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Learning Behavior-driven Development with JavaScript un PDF/ePUB en línea?
Sí, puedes acceder a Learning Behavior-driven Development with JavaScript de Enrique Amodeo en formato PDF o ePUB, así como a otros libros populares de Computer Science y Web Services & APIs. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
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 ...

Índice