| name | commandbox-testing |
| description | Use this skill for CommandBox TestBox integration: testbox run command, running tests from CLI, configuring runner URL in box.json, multiple output formats (json/antjunit), test watcher (testbox watch), CI integration, code coverage with FusionReactor, test labels and suites, and box.json testbox configuration. |
CommandBox TestBox Integration
Overview
CommandBox has built-in integration with TestBox — the BDD/TDD testing framework for CFML/BoxLang. Run your test suite from the CLI and integrate with CI pipelines.
testbox help
Requirements
- A running server (CommandBox or external)
- TestBox installed in your project
- A test runner file (default:
/tests/runner.cfm)
install testbox --saveDev
server start
testbox run
testbox run
testbox run
testbox run "http://localhost:8080/tests/runner.cfm"
testbox run "/tests/runner.cfm"
testbox run --verbose
testbox run --noVerbose
testbox run bundles=tests.unit.MyTest
testbox run labels=unit
testbox run labels=unit,integration
testbox run testSuites=MySuite
testbox run testSpecs=itShouldDoSomething
testbox run outputformats=json,antjunit,simple
testbox run outputformats=json,antjunit outputFile=build/test-results
testbox run options:opt1=value1 options:opt2=value2
Example Output
Executing tests via http://127.0.0.1:8080/tests/runner.cfm...
TestBox v5.0.0
---------------------------------------------------------------------------
| Passed | Failed | Errored | Skipped | Time | Bundles | Suites | Specs |
---------------------------------------------------------------------------
| 42 | 0 | 0 | 2 | 320 ms | 3 | 8 | 44 |
---------------------------------------------------------------------------
Configure Runner in box.json
Set the runner URL once so testbox run works without arguments:
package set testbox.runner="http://localhost:8080/tests/runner.cfm"
package set testbox.runner="/tests/runner.cfm"
testbox run
Full box.json TestBox Configuration
{
"testbox": {
"runner": "http://localhost:8080/tests/runner.cfm",
"verbose": false,
"labels": "unit,integration",
"testSuites": "MySuite",
"testSpecs": "",
"bundles": "",
"recurse": true,
"reporter": "json",
"outputformats": "json,antjunit",
"outputFile": "build/test-results",
"watchDelay": 1000,
"watchPaths": "/models/**.cfc,/handlers/**.cfc",
"options": {
"opt1": "value1"
}
}
}
Test Watcher
testbox watch monitors files and re-runs tests on any change:
package set testbox.runner=http://localhost:8080/tests/runner.cfm
server start
testbox watch
testbox watch **.cfc
testbox watch /models/**.cfc,/handlers/**.cfc
package set testbox.watchPaths=/models/**.cfc
testbox watch
Watcher options in box.json:
package set testbox.watchDelay=500
package set testbox.verbose=false
package set testbox.labels=unit
package set testbox.watchPaths=/models/**.cfc
Stop the watcher with Ctrl+C.
CI Integration (GitHub Actions)
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup CommandBox
uses: Ortus-Solutions/setup-commandbox@v2.0.0
- name: Install Dependencies
run: box install
- name: Start Server
run: box server start --noOpenBrowser
- name: Run Tests
run: box testbox run --noVerbose outputformats=antjunit outputFile=build/test-results
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: "build/test-results*.xml"
Multiple Output Formats
| Format | Description | File Extension |
|---|
simple | Text summary (default CLI output) | .txt |
json | Full JSON test report | .json |
antjunit | JUnit-compatible XML (for CI tools) | .xml |
mintext | Minimal text output | .txt |
dot | Dot-notation summary | .txt |
testbox run outputformats=json,antjunit,simple outputFile=build/results
Code Coverage
When running on a server with FusionReactor installed and TestBox 2.9+:
testbox run
Common Patterns
Run tests before server start (recipe)
install
server start
testbox run || exit 1
recipe test-and-start.boxr
Run tests in box.json scripts
{
"scripts": {
"test": "testbox run",
"test:watch": "testbox watch",
"prePublish": "testbox run"
}
}
run-script test
run-script test:watch
Task Runner Integration
component {
function test() {
var exitCode = command( "testbox run" )
.params( verbose=false )
.run( returnExitCode=true );
if ( exitCode != 0 ) {
error( "Tests failed! Aborting build." );
}
print.greenLine( "All tests passed!" );
}
}
task run test