您的位置:首页 > 其它

FlexUnit小小应用

2008-11-04 12:46 113 查看
类似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;
}

}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: