Test-Driven Development
Iterate on Apex code with fast feedback by running aer test --watch. Watch mode keeps the test runner alive, re-executes suites when files change, and surfaces failures immediately so you can adjust your code or tests before context switches pile up.
Start watch mode
aer test force-app/main/default \
--watchThe command scans the supplied directories for Apex files and starts an incremental test loop:
- Compiles the project once to seed the in-memory schema and package cache.
- Watches Apex source, schema files, and package definitions inside the provided paths.
- Re-runs the affected tests after every successful compile.
Press Ctrl+C when you are ready to stop the session.
Focus on a slice of work
Combine --watch with existing flags to keep the loop tight:
aer test force-app/main/default \
--watch \
--filter OrderService--filternarrows execution to tests that contain the supplied substrings.--packageor--package-dirlets you load managed packages so watch mode runs against realistic dependencies.--schemaor--no-auto-schemacontrols whether watch mode bootstraps a local schema from source.
Update tests first, save the file, and aer recompiles before running the focused subset, giving you near-instant confirmation that the new expectations fail.
Keep the loop fast
Follow these cadence tips when practicing test-driven development:
- Write or modify one test at a time and commit the file before changing implementation.
- Keep the watch output visible so you notice regressions the moment they land.
- Use
--quietonce the loop is stable to hide passing output and highlight failures. - Pair
--watchwith--verbosewhen you need quick “printf” debugging; the flag streamsSystem.debugoutput so you can inspect values between runs. - Store temporary artifacts (profiles, traces) outside your repo if you combine watch mode with
--profileor--trace.
When the test goes green, repeat the cycle: refactor with confidence, save, and let watch mode validate the change. The tight feedback loop keeps you in flow while you grow Apex coverage.