View Source

h2. Getting Started with TestSuites

A TestSuite is a collection of tests that logically fit together.

h3. 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:
# Create a ColdFusion page to run the suite
# Create a TestSuite object
# Tell the TestSuite what tests to add
# run() the TestSuite
# Print the output
# Run the suite in your web browser

*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:

{code:title=MyTestSuite.cfm}<cfscript>
testSuite = createObject("component","mxunit.framework.TestSuite").TestSuite();
</cfscript>

{code}
*3. Tell the TestSuite what tests to add*

{code}<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>

{code}
*4. Run the TestSuite*
{code}<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>
{code}
*5. Do something with the output*
{code}<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>

{code}


*6. Run the suite in your web browser*

[http://localhost:8500/mxunit/doc/tutorial/mytests/MyTestSuite.cfm|http://localhost:8500/mxunit/doc/tutorial/mytests/MyTestSuite.cfm]

You should see this:

!suites-1.png!


*Next - [Overview of MXUnit TestResult output formats|TestResult Output Formats]*