Agentic Testing with TestBox
Test BoxLang and ColdBox applications with TestBox, the BDD and TDD testing and mocking framework, and let AI agents write and run tests in a fast, safe loop.
TestBox is the testing and mocking framework for BoxLang. It gives you BDD and xUnit styles, a fluent expectations library, mocking and stubbing with MockBox, multiple reporters, and a command line runner built for BoxLang.
Tests matter even more when AI agents write code. Tests are the objective check that tells you, and the agent, that the code actually works.
🔁 The Agentic Test Loop
Write, or ask the agent to write, a failing spec that describes the behavior.
Implement the code.
Validate syntax with
boxlang check.Run the specs, and feed the failures back to the agent.
Repeat until green.
📦 Install
With CommandBox:
A typical project layout:
Bundles are discovered by name. The default pattern matches files such as *Spec*.bx, *Test*.bx, *Spec*.cfc, and *Test*.cfc, and the default directory is tests.specs.
🧪 Writing Specs
BDD
Behavior-driven specs read like documentation:
describe(), it(), beforeEach(), afterEach(), aroundEach(), nested suites, labels, and skip and focus flags are all supported. feature(), story(), given(), when(), and then() are aliases for a Given-When-Then style.
xUnit
Prefer classic test methods? Name them test*:
✅ Expectations
The fluent expect() API covers equality, types, strings, collections, exceptions, and more. TestBox 7.1 added:
Grouped assertions so one spec can report several failures at once
Collection modes
expectAll,expectAny,expectSome, andexpectNonewithContext()to attach a message to an expectationNew matchers such as
toBeTruthy,toBeFalsy,toBeSameInstanceAs,toHaveSize, andtoThrowMatchingBoxLang-only matchers for Sets, Ranges, and data navigation with paths
See the TestBox 7.1 release notes for details.
🎭 Mocking With MockBox
MockBox creates mocks and stubs so you can test a unit in isolation:
Useful methods include $() to mock a method, $args() to match arguments, $results() and $throws() to control returns, $callback() for custom logic, $spy() to observe a real method, and $count(), $times(), $never(), and $callLog() to verify calls.
🏃 Running Tests
BoxLang CLI Runner
The BoxLang runner needs no web server:
--directory, --bundles
What to run
--labels, --excludes
Run or skip labeled suites
--filter-bundles, --filter-suites, --filter-specs
Narrow to a specific bundle, suite, or spec
--reporter
Choose a reporter such as console or json
--dry-run
Discover tests without running them
--eager-failure
Stop at the first failure
--verbose
Detailed progress
--write-report, --write-json-report, --reportpath
Write reports to disk
Pass bundles as --bundles=... rather than as a bare argument.
CommandBox
testbox watch reruns tests as files change. If your specs use BoxLang-only features, prefer the BoxLang CLI runner, since the CommandBox runner may execute through a CFML engine.
Reporters
TestBox includes many reporters, including console, json, junit, xml, tap, text, min, and dots. Use junit or json in CI.
TestBox RUN
TestBox also ships a browser-based test IDE and a streaming runner that reports results as they complete. See the TestBox documentation.
🤖 Let Agents Drive the Tests
Options that make the runner fast and easy for an agent to read:
Install the Testing Skill
The skill teaches your agent BDD and xUnit structure, expectations, MockBox, and lifecycle hooks. See Skills & Guidelines.
Tell the Agent in AGENTS.md
Prompt Recipes
🧱 Testing ColdBox Applications
ColdBox tests extend BaseModelTest for unit tests of models and BaseIntegrationTest for full request tests against handlers, routes, and views. See Agentic MVC with ColdBox.
📊 Coverage
TestBox coverage relies on FusionReactor and is opt-in. It applies to the CFML runner, so check the code coverage documentation for what your setup supports.
🚦 Continuous Integration
Run the same commands in CI that you run locally, syntax check first:
Publish the JUnit output with your CI provider's test reporting.
📚 Resources
Last updated
Was this helpful?
