contents

preface

acknowledgments

about this book

about the author

about the cover illustration

Part 1. Testing JavaScript applications

  1 An introduction to automated testing

  1.1  What is an automated test?

  1.2  Why automated tests matter

Predictability

Reproducibility

Collaboration

Speed

  2 What to test and when?

  2.1  The testing pyramid

  2.2  Unit tests

  2.3  Integration tests

  2.4  End-to-end tests

Testing HTTP APIs

Testing GUIs

Acceptance tests and end-to-end tests are not the same

  2.5  Exploratory testing and the value of QA

  2.6  Tests, cost, and revenue

Part 2. Writing tests

  3 Testing techniques

  3.1  Organizing test suites

Breaking down tests

Parallelism

Global hooks

Atomicity

  3.2  Writing good assertions

Assertions and error handling

Loose assertions

Using custom matchers

Circular assertions

  3.3  Test doubles: Mocks, stubs, and spies

Mocking imports

  3.4  Choosing what to test

Don’t test third-party software

To mock, or not to mock: That’s the question

When in doubt, choose integration tests

  3.5  Code coverage

Automated coverage reports

Coverage types

What coverage is good for and what it isn’t

  4 Testing backend applications

  4.1  Structuring a testing environment

End-to-end testing

Integration testing

Unit testing

  4.2  Testing HTTP endpoints

Testing middleware

  4.3  Dealing with external dependencies

Integrations with databases

Integrations with other APIs

  5 Advanced backend testing techniques

  5.1  Eliminating nondeterminism

Parallelism and shared resources

Dealing with time

  5.2  Reducing costs while preserving quality

Reducing overlap between tests

Creating transitive guarantees

Turning assertions into preconditions

  6 Testing frontend applications

  6.1  Introducing JSDOM

  6.2  Asserting on the DOM

Making it easier to find elements

Writing better assertions

  6.3  Handling events

  6.4  Testing and browser APIs

Testing a localStorage integration

Testing a History API integration

  6.5  Dealing with WebSockets and HTTP requests

Tests involving HTTP requests

Tests involving WebSockets

  7 The React testing ecosystem

  7.1  Setting up a test environment for React

Setting up a React application

Setting up a testing environment

  7.2  An overview of React testing libraries

Rendering components and the DOM

React Testing Library

Enzyme

The React test renderer

  8 Testing React applications

  8.1  Testing component integration

Stubbing components

  8.2  Snapshot testing

Snapshots beyond components

Serializers

  8.3  Testing styles

  8.4  Component-level acceptance tests and component stories

Writing stories

Writing documentation

  9 Test-driven development

  9.1  The philosophy behind test-driven development

What test-driven development is

Adjusting the size of your iterations

Why adopt test-driven development?

When not to apply test-driven development

  9.2  Writing a JavaScript module using TDD

  9.3  Testing top-down versus testing bottom-up

What bottom-up and top-down testing mean

How top-down and bottom-up approaches impact a test-driven workflow

The pros and cons of bottom-up versus top-down approaches

  9.4  Balancing maintenance costs, delivery speed, and brittleness

Test-driven implementation

Test-driven maintenance

  9.5  Setting up an environment for TDD to succeed

Teamwide adoption

Keeping distinct lanes

Pairing

Supplementary testing

  9.6  TDD, BDD, validations, and specificationsBDD (behavior-driven development)

10 UI-based end-to-end testing

10.1  What are UI-based end-to-end tests?

10.2  When to write each type of test

UI-based end-to-end tests

Pure end-to-end tests

Pure UI tests

A note on acceptance testing and this chapter’s name

10.3  An overview of end-to-end testing tools

Selenium

Puppeteer

Cypress

When to choose Cypress

11 Writing UI-based end-to-end tests

11.1  Your first UI-based end-to-end tests

Setting up a test environment

Writing your first tests

Sending HTTP requests

Sequencing actions

11.2  Best practices for end-to-end-tests

Page objects

Application actions

11.3  Dealing with flakiness

Avoiding waiting for fixed amounts of time

Stubbing uncontrollable factors

Retrying tests

11.4  Running tests on multiple browsers

Using a testing framework to run tests within a browser

Running UI-based tests in multiple browsers

11.5  Visual regression tests

Part 3. Business impact

12 Continuous integration and continuous delivery

12.1  What are continuous integration and continuous delivery?

Continuous integration

Continuous delivery

12.2  The role of automated tests in a CI/CD pipeline

12.3  Version-control checks

13 A culture of quality

13.1  Using type systems to make invalid states unrepresentable

13.2  Reviewing code to catch problems machines can’t

13.3  Using linters and formatters to produce consistent code

13.4  Monitoring your systems to understand how they actually behave

13.5  Explaining your software with good documentation

  

index

  

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
44.210.239.12