Your FlexUnit 4 tests can be run in a number of ways. The Basic Test tutorial goes over the method of running it with the tool within Flash Builder 4. Here we will discuss that way as well as a few others in greater details.
Using Test Runner UI
(In Flash Builder 4)
- Open up your main application file for your Test Project.
- Import FlexUnitCore and any Tests or Suites you wish to run your imports should look similar to the following:
import sampleSuite.SampleSuite; import sampleSuite.tests.SimpleTest; import org.flexunit.runner.FlexUnitCore;
- You will need to declare a variable for FlexUnitCore which should be private.
- Create a protected function called startTestProcess.
- Inside the function you'll want to instantiate core with a new FlexUnitCore.
- Next you'll need to add a listener to core for the TestRunner class which will display the tests in a UI when run.
- Then call the method run on core passing the class SampleSuite as an argument.
- Your startTestProcess method should look like the following.
private var core : FlexUnitCore; protected function startTestProcess():void { core = new FlexUnitCore(); //Listener for the UI core.addListener( new UIListener( uiListener )); core.run( SampleSuite ); }
Before you can build you will also need to add the following mxml tag for TestRunnerBase named uiListener.
<code:xml>
<flexUnitUIRunner:TestRunnerBase id="uiListener"
width="100%" height="100%" />
In order to be certain your tests run on application startup, you'll want to add your function to the creationComplete listener <code>Application</code> tag which should look similar to the following: {code:actionscript} <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" xmlns:flexUnitUIRunner="http://www.adobe.com/2009/flexUnitUIRunner" minWidth="955" minHeight="600" creationComplete="startTestProcess()" xmlns:flexui="flexunit.flexui.*">
At this point you can simply run your tests normally and the browser will display a UI interface with a progress bar and trace window for tests. This interface is identical to the UI runner for Fluint.