Avg. Rating 3.3

Problem

How to add a TestCase to an existing TestSuite?

Solution

Use the TestSuite addTestSuite method.

Detailed explanation

This recipe extends the Create an application to run FlexUnit tests  and Create a FlexUnit TestCase recipes.

To add your TestCase to the TestSuite use the addTestSuite method. This method takes in a reference to the TestCase class. Behind the scenes FlexUnit uses reflection to find all methods that start with test and add them to be executed.

The following updated createSuite method adds RegExpTest to the set of tests to be executed:

            private function createTestSuite():TestSuite
            {
                var testSuite:TestSuite = new TestSuite();
                testSuite.addTestSuite(RegExpTest);
                return testSuite;
            }

If the TestCase is not in the default package, be sure to add an import for the class. For example:
            import mx.core.UITextFormatTest;
           
            private function createTestSuite():TestSuite
            {
                var testSuite:TestSuite = new TestSuite();
                testSuite.addTestSuite(RegExpTest);
                testSuite.addTestSuite(UITextFormatTest);
                return testSuite;
            }
Multiple TestCases can be added to a TestSuite and they will all be run in the order added.
Report abuse

Related recipes