This course is an introduction to and exploration of testing for the web.
In this course, you'll learn about the following:
- Testing fundamentals
- Automated versus manual testing
- Where and how to run your tests
- Best practices
- The philosophy of testing, including what to test, who's responsible, and how to consider testing a means to an end, not as an objective itself.
The course also includes concise, practical sample code to learn from.
Because most testing frameworks and tools share a common language, Learn Testing takes a general approach to testing. Where it's important to get specific, we'll use Vitest, a test framework that's growing in popularity, and demonstrate how to test components for the web written using React or Lit. To learn more about this choice, see the appendix.
You can go through this course from beginning to end, but you can also use it as a reference for specific topics. Where relevant, the course links to resources.
Here's what you'll learn:
Get started with testing
Tests can help you be productive and write software efficiently, and while it's possible to run them manually using a command line, you can also run them as part of an automated process or build system.
Runtime tools like Node are for general-purpose code, and testing code for the browser can either be run in an emulated environment or using a framework designed for browser testing.
Learn about common categorizations of test types, which mostly correspond to their scale. Importantly, test types don't have a strict definition and will change based on your needs.
Identifying the most important parts of your codebase to apply rigorous testing to can be a tough decision. This module introduces the idea of testing as a means to an end, and how to assess your code for testing.
In this practical module, you'll learn how to test a not-so-ideal React
component. This uses Vitest through three distinct examples: intercepting
network traffic made with
fetch(), mocking an external dependency, and using
Context to provide a custom bit of code just for the test.
Using tools like TypeScript and ESLint, while not well-established approaches to testing, can provide a type of automated checking. This module discusses these alternative tools.
Assertions and other primitives
Learn about the primitives common to most testing libraries or frameworks,
assert, that will be mainstays of every test you write
- Avoid common test pitfalls
- Test doubles
- Test libraries and utilities
- Decide on a test framework
The remainder of this section will contain more pages on test frameworks and libraries, the way they should be used, and how to decide on which one and what other tools to use.
Coming soon: Problem-driven testing
You'll learn patterns to approach a number of common Web testing challenges.
Coming soon: Automated testing in practice
This is a practical section showing how to test an ecommerce site built with Next.js, including code you can check out and learn yourself. You'll learn how to test its components, how to work with its external services, including payment, for testing, and how to build end-to-end tests for a site that has an optional login page.
Coming soon: The philosophy of testing
Testing can be an engineering challenge, but knowing what to test, who's responsible, and best practices can also be a challenge for a development team.
Coming soon: Writing testable code
This course provides guidance on testing code as it exists, but your team can adopt various patterns to make your code easier to test. This section will cover some approaches.