Testing
Testing Overview
JCC Express MVC ships with a Laravel-style testing layer that lets you test your application through real HTTP requests and database assertions — no mocking required.
How it works
Each feature test:
- Boots a full
Applicationinstance (your real routes, middleware, providers) - Starts a temporary HTTP server on a random port
- Makes real
fetch()requests against it - Wraps the result in
TestResponseso you can make fluent assertions - Tears the server down after each request automatically
Database state is isolated using withTransaction, which rolls back after every test body.
Two test runners — important
| Runner | Command | Used for |
|---|---|---|
vitest | npm run test | Unit tests (tests/Unit/) |
bun test | bun test tests/Feature | Feature tests (tests/Feature/) |
Feature tests import from bun:test and cannot run under Vitest. vitest.config.ts excludes tests/Feature/** for this reason. Always use bun test for feature tests.
Core classes
| Class | Role |
|---|---|
TestCase | Boots app, exposes HTTP + DB helpers |
MakesHttpRequests | HTTP helper — get, post, put, patch, delete |
TestResponse | Fluent response assertions |
InteractsWithDatabase | DB assertions |
Factory + Faker | Test data generation |
Project test structure
TypeScript
Generate a test
Bash
Creates a starter file in tests/Feature/.