
498Testing
nience when you’re working with a lot of test cases. Listing 23.7 shows an example of
a test-runner application.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
xmlns:flexunit="flexunit.flexui.*" >
<mx:Script>
<![CDATA[
import flexunit.framework.TestSuite;
private function runTests():void
{
var ts:TestSuite = new TestSuite();
ts.addTest( myTest.suite() );
testRunner.test = ts;
testRunner.startTest();
}
] ] >
</mx:Script>
<mx:Button label="Begin Tests" click="runTests()"/>
<flexunit:TestRunnerBase id="testRunner"
width="100%" height="100%" />
</mx:Application>
Now all you need to do is create the test cases.
CREATING A TEST CASE
The last piece involves scripting your test cases by creating ActionScript classes that
return a test suite containing all the necessary tests. You can make one big test suite
with many test cases, or you can make many test suites with fewer test cases—whatever
is easier for you.
In this test-runner example, you invoke a test suite called
myTest,
shown in
listing 23.8.
package {
import flexunit.framework.TestCase;
import flexunit.framework.TestSuite;
public class myTest extends TestCase {
public function myTest( methodName:String ) {
super( methodName );
}
public static function suite():TestSuite {
var ts:TestSuite = new TestSuite();
Listing 23.7 Setting up a FlexUnit test runner
Listing 23.8 myTest.as: Sample FlexUnit test suite with a number of test cases
Call addTest() function as
needed to add TestSuites
Add FlexUnit MXML
visual component
Commenti su questo manuale