类似JUnit,之前稍微研究过。现在简单介绍下FlexUnit的简单应用:首先去adobe open source下载FLEXUNIT
网址:http://opensource.adobe.com/wiki/display/flexunit/Downloads
在你建立好的项目中导入该swc,(此步骤就不介绍了^-^).
index.mxml (亦可是别的mxml)模拟:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:flexui="flexunit.flexui.*"
creationComplete="init()" layout="absolute" >
<mx:Script>
<![CDATA[
//import some class yourself
private function createTestSuite():TestSuite
{
var testSuite:TestSuite = new TestSuite();
testSuite.addTest(new SimpleTest("testConvertIsDesc"));
return testSuite;
}
internal function init():void
{
///TestUnit//
testRunner.test = createTestSuite();
testRunner.startTest();
/
}
]]>
</mx:Script>
<flexui:TestRunnerBase id="testRunner" width="100%" height="100%"/>
</mx:Application>
SimpleTest.as------>code
package com.jerry.tests
{
import flexunit.framework.TestCase;
import flexunit.framework.Assert;
public class SimpleTest extends TestCase
{
public function SimpleTest(methodName:String=null)
{
super(methodName);
}
// 测试方法 ConvertToIsDesc
public function testConvertIsDesc():void
{
var simple:SimpleConverter = new SimpleConverter();
var desc:String = simple.ConvertToIsDesc(1);
Assert.assertEquals(desc, "是");
}
}
SimpleConverter.as---->code
package com.jerry.tests
{
public class SimpleConverter
{
public function SimpleConverter()
{
// 构造函数
}
// 需要测试的方法
public function ConvertToIsDesc(i:int):String
{
var isDesc:String = "否";
if(i == 1)
{
isDesc = "是";
}
return isDesc;
}
}
}
}