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.
Unit Tests
E2E Tests
Testing Stack
The starter kit uses modern testing tools:
- Vitest: Fast unit testing framework built on Vite
- Playwright: Reliable end-to-end testing framework
- Testcontainers: For database integration tests
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 utilitiesRunning Tests
Unit Tests
Run all unit tests:
npm run test:unitRun tests in watch mode:
npm run test:watchGenerate coverage report:
npm run test:coverageE2E Tests
Run E2E tests:
npm run test:e2eRun E2E tests with UI:
npm run test:e2e:uiRun E2E tests in debug mode:
npm run test:e2e:debugDatabase Tests
Run database integration tests (requires Docker):
npm run test:dbTest Configuration
Vitest Configuration
The Vitest configuration is in vitest.config.mts:
- Uses
vite-tsconfig-pathsfor path resolution - Includes tests from
tests/**/*.{test,spec}.?(c|m)[jt]s?(x)andlib/**/*.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.