Stub vs Spy
intermediateDefinition
Two test helpers, often confused. A stub replaces a real function with a fake one that always returns whatever the test wants: used to control what the code sees. A spy doesn't change anything; it lets the real function run and just quietly takes notes about how it was called: used to check that the right calls happened.
In the wild
Testing a 'show user profile' page. The test uses a stub to make the 'fetch user' function always return the same fake user, so the test isn't dependent on a real database. Separately, it uses a spy on the 'log analytics' function: the real one runs, but the spy keeps track of what it was told to log so the test can confirm a 'profile viewed' event was sent.
More from Testing & Quality
Assertion
A statement inside a test that says 'I expect this to be true.' If the expectation is wrong, the test fails and tells you exactly what didn't match. Assertions are how a test actually checks that the code is doing what it's supposed to.
End-to-End (E2E) Test
A test that drives the whole app from the outside, just like a real person would: clicking buttons, filling out forms, going from one page to the next. It's the most realistic kind of test (it catches problems no other test would), but also the slowest and the most easily upset by little changes.
Fixture
A pre-prepared piece of fake data that tests can rely on: like a sample user, a stock list of products, or a saved response. Using the same fixture across many tests keeps them tidy and consistent, instead of every test inventing its own slightly different sample.
Flaky Test
A test that sometimes passes and sometimes fails for no clear reason: usually because it depends on something it shouldn't, like the time of day, the order other tests ran in, or how fast the network is responding. Flaky tests slowly destroy the team's trust in the whole test suite.
Integration Test
A test that checks whether several pieces of an app work correctly when they're put together: talking to a real database, hitting a real internal service, the way they would in real life. It catches the kinds of bugs that only show up when separate pieces have to cooperate.
Linting
Automatic proofreading for code. A linter scans through the source files and flags stylistic mistakes, suspicious patterns, and likely bugs: without actually running the code. It catches the small problems early, before they reach reviewers or tests.