50 cards
Software testing is organized around three principal levels of scope, each targeting different parts of the system. A unit test verifies the behavior of a single, isolated piece of code such as a function or method. It runs in milliseconds, uses mocked or stubbed dependencies, and is deterministic and repeatable. An in...
Test-Driven Development, or TDD, is a development practice in which tests are written before production code. The cycle begins with Red, writing a failing test that describes the desired behavior. The next step, Green, involves writing the minimum code necessary to make the test pass. The cycle concludes with Refactor,...
Tests often need to replace real dependencies to isolate the code under test. These replacements are called test doubles, a term coined by Gerard Meszaros in xUnit Test Patterns, and come in five varieties. A dummy object is a placeholder passed around but never used, often just filling required parameters. A stub prov...
Well-structured tests follow clear patterns that aid readability and maintenance. The AAA pattern, which stands for Arrange, Act, Assert, divides a test into three phases: Arrange sets up the test data, mocks, and preconditions; Act executes the code under test; and Assert verifies the expected outcome. For example, a...
Behind every robust test suite lies infrastructure that prepares and cleans up the environment. Test fixtures provide a fixed, known starting state by supplying predefined data, object instances in a known configuration, or environment settings. The arrangement of fixtures is controlled through setup and teardown hooks...
Coverage metrics attempt to quantify how thoroughly a test suite exercises the codebase. Test coverage is the umbrella term, commonly broken down into line coverage, which measures the percentage of lines executed during testing; branch coverage, which measures whether each branch of every decision point (if, else, swi...
Beyond the unit/integration/E2E tiers, several specialized testing strategies target specific risks. Regression testing re-runs existing suites after changes to catch unintended side effects and is often automated in CI/CD pipelines. It can be performed as a full regression, running every test; as a selective regressio...