Testing Overview
What software testing is, why it matters, and how it keeps your code reliable and maintainable.
What you'll learn
- What software testing means and why every developer must do it
- The cost of bugs and how testing reduces risk early
- The testing pyramid: unit, integration, and end-to-end tests
- How testing fits into the development workflow
Concept
What Is Software Testing?
Software testing is the practice of verifying that your code behaves the way you intend. A test is a small, automated program that runs a piece of your real code, feeds it inputs, and checks that the outputs match your expectations. When a test passes, you gain confidence that the code works; when it fails, you get a precise signal that something is broken and where.
Why Testing Matters
Bugs are cheapest to fix when they are caught immediately by the developer who wrote the code. The later a bug is discovered — in code review, in QA, in production, or by a paying customer — the more expensive it becomes, sometimes by orders of magnitude. Testing gives you a fast feedback loop: you run a command and within seconds know whether your change is safe. Tests also act as living documentation, showing how a function is expected to be used, and they form a safety net that lets you refactor without fear.
The Testing Pyramid
The classic testing pyramid suggests many unit tests at the base (fast, isolated, cheap), fewer integration tests in the middle (verify modules work together), and very few end-to-end tests at the top (simulate real user journeys, slow and brittle). Inverting the pyramid — relying mostly on slow end-to-end tests — leads to long, flaky test suites. A balanced pyramid gives you speed at the bottom and confidence at the top.
Testing in the Workflow
Modern teams write tests alongside or even before production code. Tests run on every save locally and on every push in continuous integration. This lesson series will take you from the core concepts to concrete tools like Vitest and Jest, through test doubles, coverage, TDD, and finally to strategies for testing components, hooks, APIs, and accessibility.
In Practice
Starting out, you do not need a framework — Node's built-in assert module is enough to write your first test and feel the feedback loop. As your project grows, adopt a framework (Vitest or Jest) to get watch mode, mocking, and reporters. Begin by testing the pure functions that hold your business logic: calculations, validations, transformations. These are the cheapest to test and the most valuable to get right. Resist the urge to test everything through the UI; push assertions down to the layer where the logic actually lives. Over the rest of this series you will build the vocabulary and habits that make testing a natural, everyday part of writing software rather than a chore bolted on at the end.
Example
// A minimal test written with Node's built-in assert module.
import assert from "node:assert/strict";
function add(a, b) {
return a + b;
}
// Arrange — set up the inputs
const expected = 5;
// Act — call the code under test
const actual = add(2, 3);
// Assert — verify the result
assert.equal(actual, expected, "add(2, 3) should equal 5");
console.log("Test passed: add works correctly");
Every test follows the Arrange-Act-Assert pattern: set up inputs, run the code, then verify the output. Node's assert module is the simplest way to start without any framework.
Try it
- Code Diff
Compare expected vs actual output to understand test failures.
- JSON Formatter
Inspect the structured data your tests often compare.
Common mistakes
The mistake
Treating testing as optional or 'only for QA'
The fix
Testing is a core developer skill. Write tests as you write code — they are part of the deliverable, not an afterthought.
The mistake
Writing only end-to-end tests because they feel 'real'
The fix
Start with fast unit tests for logic, add integration tests for boundaries, and keep end-to-end tests few and focused. Follow the pyramid.
Practice Testing Overview
2 exercises
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.