Skip to content

Test Runner

In one line

A test runner is the tool that runs your tests, collects results, and shows pass/fail output. Examples: Jest, Mocha, Vitest.

In simple words

A test runner is the engine of your testing setup. It does the mechanical work:

  1. Discovery: Finds all your test files (usually by naming convention like *.test.js).
  2. Execution: Runs each test case in the right environment.
  3. Reporting: Shows you which tests passed, which failed, and how long they took.
  4. Watch mode: Optionally re-runs tests when files change.

Popular test runners include:

  • Jest: All-in-one (runner + assertion library + mocking), most popular for JavaScript/React.
  • Mocha: Flexible runner that needs separate assertion and mocking libraries.
  • Vitest: Fast, Vite-native test runner, Jest-compatible API.

The test runner is what you invoke when you run npm test.

Example

javascript
// package.json — configure a test runner
{
  "scripts": {
    "test": "vitest run",
    "test:watch": "vitest"
  }
}

// Run via CLI:
// $ npx vitest run
//  ✓ src/math.test.js (2)
//  Test Files  1 passed (1)
//       Tests  2 passed (2)
//    Duration  120ms

// The test runner discovers *.test.js files,
// executes each test() block, and reports results.

A test runner (here Vitest) discovers test files, executes each test block, collects pass/fail results, and prints a summary. You configure it in package.json and invoke it via the CLI.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary