Course contentsShow
← Software Engineering
Lesson 463 of 1,93313. Unit Testing in DepthFree lesson

Separating Slow Tests from Fast Tests

Organizing test suites to run fast unit tests frequently while isolating slower integration tests.

Separating Slow Tests from Fast Tests

What You'll Learn

You'll learn how to organize your test suite so fast unit tests run frequently during development while slower integration tests run separately.

The Two-Speed Test Problem

Not all tests are created equal. Unit tests typically run in milliseconds, but integration tests—those hitting databases, APIs, or filesystems—can take seconds or even minutes. When every code change triggers the entire suite, slow tests kill productivity.

The analogy: Imagine checking your spelling after every sentence (fast) versus sending your entire manuscript to an editor after every sentence (slow). You'd never finish writing!

The Solution: Test Categories

Separate your tests into distinct groups:

  • Fast tests – Pure unit tests with no I/O, run constantly
  • Slow tests – Integration/E2E tests, run less frequently

Most testing frameworks support tags, markers, or naming conventions:

tests/
  unit/          # Fast tests here
  integration/   # Slow tests here

Or use test markers/annotations:

@Tag("fast")
testUserNameValidation() { ... }

@Tag("slow") 
testDatabaseConnection() { ... }

When to Run Each

  • Fast tests: Run on every file save, before every commit, constantly during TDD
  • Slow tests: Run before pushing to main branch, during CI builds, nightly

The Developer Workflow

With separation, developers get instant feedback from fast tests (seconds) while still maintaining confidence from comprehensive slow tests (minutes) that run less often. You maintain the testing pyramid's benefits without sacrificing development speed.

Key Takeaway: Separate fast unit tests from slow integration tests so you can run them at different frequencies—maintaining rapid feedback loops while still ensuring comprehensive coverage.