[地址:http://opensource.adobe.com/wiki/display/flexunit/Downloads] 并在应用中加入库文件:
目前版本为0.9, 下载完解压缩之后, 在Flex或AIR工程的Flex Build Path的Library Path中加入FlexUnit.swc库文件.
待测试的单元:
package { public class SimpleConverter { public function SimpleConverter() { } public function convertToString(i:int):String { var s:String = "错误!" if(i == 1) { s = "是"; }else { s = "否"; } return s; } } }
测试用例:
package { import flexunit.framework.Assert; import flexunit.framework.TestCase; public class TestSimpleConverter extends TestCase { public function TestSimpleConverter(methodName:String=null) { super(methodName); } /** * 测试用例 */ public function testSimpleConverter():void { var sc:SimpleConverter = new SimpleConverter(); var s:String = sc.convertToString(1); Assert.assertEquals(sc.convertToString(1), "是"); } } }
import flexunit.framework.TestSuite; private function onCreateComplete():void { var ts:TestSuite = new TestSuite(); ts.addTest(new TestSimpleConverter("testSimpleConverter")); testRunner.test = ts; testRunner.startTest(); }
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.