Generate test files for models, controllers, views, and other components.
The wheels generate test
command creates test files for various components of your Wheels application. It generates appropriate test scaffolding based on the component type and includes common test cases to get you started.
Generates /tests/models/ProductTest.cfc
:
Generates /tests/controllers/ProductsTest.cfc
:
Generates a test for the products/index view.
Generates complete CRUD test methods for the controller.
Generates /tests/views/products/IndexTest.cfc
:
Generates additional integration tests:
Focus on:
Validations
Associations
Callbacks
Scopes
Custom methods
Data integrity
Focus on:
Action responses
Parameter handling
Authentication/authorization
Flash messages
Redirects
Error handling
Focus on:
Content rendering
Data display
HTML structure
Escaping/security
Conditional display
Helpers usage
Creates /tests/fixtures/products.cfc
:
Test in isolation: Each test should be independent
Use descriptive names: Test names should explain what they test
Follow AAA pattern: Arrange, Act, Assert
Clean up data: Use setup/teardown or transactions
Test edge cases: Empty data, nulls, extremes
Mock external services: Don't rely on external APIs
Keep tests fast: Optimize slow tests
Test one thing: Each test should verify one behavior
Use fixtures wisely: Share common test data
Run tests frequently: Before commits and in CI
wheels test run - Run tests
wheels test coverage - Test coverage
Testing Guide - Testing documentation