This directory contains the test suite for your Wheels application using TestBox.
# Model test
wheels generate test model User
# Controller test with CRUD
wheels generate test controller Users --crud
# API test
wheels generate test api v1.users# Run all tests
box testbox run
# Run specific directory
box testbox run --directory=tests/specs/unit
# Watch mode for TDD
box testbox watchOr visit: http://localhost/tests/runner.cfm
component extends="wheels.WheelsTest" {
function run() {
describe("My Feature", () => {
it("should work as expected", () => {
expect(true).toBeTrue();
});
});
}
}BaseSpec.cfc- Base test class with Wheels helpersrunner.cfm- Web-based test runnerspecs/- Test specificationsunit/- Isolated unit testsintegration/- Integration testsfunctional/- End-to-end tests
fixtures/- Test data and fixturessupport/- Test utilities and factories
describe("User Model", () => {
beforeEach(() => {
variables.user = model("User").new();
});
it("should validate email", () => {
user.email = "invalid";
expect(user.valid()).toBeFalse();
assertHasErrors(user, "email");
});
});describe("UsersController", () => {
it("should list users", () => {
var result = processRequest(
route = "users",
method = "GET"
);
expect(result.status).toBe(200);
});
});// Create and save
var user = create("user", {role: "admin"});
// Build without saving
var product = build("product");
// Create multiple
var orders = createList("order", 5);model(name)- Get a model instancecontroller(name)- Get a controller instancecreate(factory, attributes)- Create test databuild(factory, attributes)- Build without savingprocessRequest(route, method, params)- Process HTTP requestloginAs(userId)- Login as user for testingassertHasErrors(model, property)- Assert validation errors
# Migrate a single file
wheels test migrate path/to/test.cfc
# Migrate all tests
wheels test migrate tests --recursive- Tests run in transactions that roll back automatically
- Use descriptive test names that explain the behavior
- Follow the AAA pattern: Arrange, Act, Assert
- Run tests before committing code
- Use
fit()to focus on a single test during development
For comprehensive documentation, see: