A TestSuite is a collection of tests that logically fit together.
Creating and Running a TestSuite
MXUnit was built to make it as easy as possible to create tests and test suites.
For this tutorial we will incrementally rebuild the MXUnit example found in
the installation package mxunit/samples/MyTestSuite.cfm
.
The steps for creating and running a TestSuite are:
1. Create a ColdFusion page to run this example
Create an empty ColdFusion page and save it as MyTestSuite.cfm in
/mxunit/doc/tutorial/mytests
2. Create a TestSuite object
Type the following code into the template:
<cfscript> testSuite = createObject("component","mxunit.framework.TestSuite").TestSuite(); </cfscript>
3. Tell the TestSuite what tests to add
<cfscript> testSuite = createObject("component","mxunit.framework.TestSuite").TestSuite(); //Add all runnable methods in MyComponentTest testSuite.addAll("mxunit.samples.MyComponentTest"); testSuite.addAll("mxunit.samples.MyOtherComponentTest"); //Identical to above //add explicit test cased (don't start with 'test'). //Note you can add more than one at a time as a list testSuite.add("mxunit.samples.MyOtherComponentTest","aTestFunctionThatDoesNotBeginWithTest,anotherTestFunctionThatDoesNotBeginWithTest"); </cfscript>
4. Run the TestSuite
<cfscript> testSuite = createObject("component","mxunit.framework.TestSuite").TestSuite(); testSuite.addAll("mxunit.samples.MyComponentTest"); testSuite.addAll("mxunit.samples.MyOtherComponentTest"); testSuite.add("mxunit.samples.MyOtherComponentTest","aTestFunctionThatDoesNotBeginWithTest,anotherTestFunctionThatDoesNotBeginWithTest"); //Run the tests and save everything in "results" results = testSuite.run(); </cfscript>
5. Do something with the output
<cfscript> testSuite = createObject("component","mxunit.framework.TestSuite").TestSuite(); testSuite.addAll("mxunit.samples.MyComponentTest"); testSuite.addAll("mxunit.samples.MyOtherComponentTest"); //Identical to above testSuite.add("mxunit.samples.MyOtherComponentTest","aTestFunctionThatDoesNotBeginWithTest,anotherTestFunctionThatDoesNotBeginWithTest"); results = testSuite.run(); //Now print the results. Simple! writeOutput(results.getResultsOutput('html')); //See next section for other output formats </cfscript>
6. Run the suite in your web browser
http://localhost:8500/mxunit/doc/tutorial/mytests/MyTestSuite.cfm
You should see this: