General
Testing

Overview

Learn about the testing setup and how to write tests for your application.

The Pro Next.js Prisma starter kit includes a comprehensive testing setup with unit tests and end-to-end (E2E) tests to help you build reliable applications.

Testing Stack

The starter kit uses modern testing tools:

Test Structure

Tests are organized in the tests/ directory:

tests/
  e2e/              # End-to-end tests (Playwright)
  lib/              # Unit tests for utility functions
  trpc/             # tRPC router tests
  support/          # Test setup and utilities

Running Tests

Unit Tests

Run all unit tests:

Terminal
npm run test:unit

Run tests in watch mode:

Terminal
npm run test:watch

Generate coverage report:

Terminal
npm run test:coverage

E2E Tests

Run E2E tests:

Terminal
npm run test:e2e

Run E2E tests with UI:

Terminal
npm run test:e2e:ui

Run E2E tests in debug mode:

Terminal
npm run test:e2e:debug

Database Tests

Run database integration tests (requires Docker):

Terminal
npm run test:db

Test Configuration

Vitest Configuration

The Vitest configuration is in vitest.config.mts:

  • Uses vite-tsconfig-paths for path resolution
  • Includes tests from tests/**/*.{test,spec}.?(c|m)[jt]s?(x) and lib/**/*.test.ts
  • Excludes database tests unless RUN_DB_TESTS=true
  • Uses Testcontainers for database tests when enabled

Playwright Configuration

The Playwright configuration is in playwright.config.ts:

  • Tests located in ./tests/e2e
  • Automatically builds and starts the app for testing
  • Uses Chromium by default
  • Includes video recording and tracing for failed tests

Best Practices

Write focused unit tests

Unit tests should test individual functions or components in isolation. Keep them fast and focused on specific behavior.

Use E2E tests for user flows

E2E tests should cover complete user journeys, not individual components. They're slower but catch integration issues.

Test critical paths

Focus on testing the most important user flows and business logic. Don't try to achieve 100% coverage.

Keep tests maintainable

Write clear, readable tests that serve as documentation. If a test is hard to understand, refactor it.

Next Steps

Ready to start writing tests? Check out the guides for Unit Tests and E2E Tests to learn more.