All pages
Powered by GitBook
1 of 3

Loading...

Loading...

Loading...

Test Runner

Run unit test suite from the command line

There is a testbox run command available that will run your unit or integration tests from the command line. All you need is to have your server running (it doesn't have to be a CommandBox server).

Run your test suite like so (modify the runner URL to match your site).

This will hit your runner URL and output a CLI-formatted report of your test results. If your test suite failed, the command will also return a failing status code when being run from your native shell. This makes integrations with CI tools like Jenkins or Travis-CI very easy since a failing test will fail your build automatically.

Default runner URL

You can also set up the default runner URL in your box.json and it will be used for you. Setting the URL is a one-time operation.

You can also use a relative path and CommandBox will look up the host and port from your server settings.

The default runner URL of the testbox run command is /tests/runner.cfm so there's actually no need to even configure it if you're using the default convention location for your runner.

Multiple Output Formats

You can run your tests and post-produce many reporting results, great for CI purposes

Arbitrary URL options

You can set arbitrary URL options in our box.json like so

You can set arbitrary URL options when you run the command like so

Both of those examples will include ?opt1=value1&opt2=value2 on the runner URL.

Additional Settings

There are a number of settings you can provide to the testbox run command to control exactly what tests run and how much output is included. Each of these can also be set in your box.json. Run this for more information.

Example Output

Here is an example of the non-verbose output.

Code Coverage

If you run tests on a server with FusionReactor installed and you are using TestBox 2.9 or greater, you will have code coverage reported in the CLI output as a percentage as well as the LOC (lines of code) that were tracked.

testbox run "http://localhost:8080/tests/runner.cfm"
package set testbox.runner="http://localhost:8080/tests/runner.cfm"
testbox run
package set testbox.runner="/tests/runner.cfm"
testbox run
testbox run outputformats=json,antjunit,simple
testbox run outputformats=json,antjunit,simple outputFile=myresults
package set testbox.options.opt1=value1
package set testbox.options.opt2=value2
testbox run options:opt1=value1 options:opt2=value2
testbox run help
testbox run --noVerbose

Executing tests via http://127.0.0.1:55197/tests/runner.cfm?&recurse=true&reporter=json, please wait...
TestBox v2.5.0+107
---------------------------------------------------------------------------------
| Passed  | Failed  | Errored | Skipped | Time    | Bundles | Suites  | Specs   |
---------------------------------------------------------------------------------
| 8       | 0       | 0       | 0       | 112 ms  | 1       | 3       | 8       |
---------------------------------------------------------------------------------

Test Watcher

This is an extension of the testbox run command but will watch the files in a directory and run the default TestBox suite on any file change.

testbox watch

In order for this command to work, you need to have started your server and configured the URL to the test runner in your box.json.

package set testbox.runner=http://localhost:8080/tests/runner.cfm
server start
testbox watch

You can also control what files to watch.

testbox watch **.cfc

If you need more control over what tests run and their output, you can set additional options in your box.json which will be picked up automatically by testbox run when it fires.

package set testbox.verbose=false
package set testbox.labels=foo
package set testbox.testSuites=bar
package set testbox.watchDelay=1000
package set testbox.watchPaths=/models/**.cfc

This command will run in the foreground until you stop it. When you are ready to shut down the watcher, press Ctrl+C.

TestBox Integration

TestBox is a next generation testing framework for ColdFusion (CFML) that is based on BDD (Behavior Driven Development) for providing a clean obvious syntax for writing tests. It contains not only a testing framework, runner, assertions and expectations library but also ships with MockBox, A Mocking & Stubbing Framework. It also supports xUnit style of testing and MXUnit compatibilities.

CLI Commands

We have a number of TestBox commands built into CommandBox to make your life easier. Check them out by requesting help on the testbox

command namespace.
https://www.ortussolutions.com/products/testbox
testbox help