售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
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
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜