FlexUnit使用 Useing FlexUnit

Categories: Flex; Tagged with: ; @ October 31st, 2008 0:07

1.下载FlexUnit

[地址:http://opensource.adobe.com/wiki/display/flexunit/Downloads] 并在应用中加入库文件:

目前版本为0.9, 下载完解压缩之后, 在Flex或AIR工程的Flex Build Path的Library Path中加入FlexUnit.swc库文件.

2. 创建测试用例

待测试的单元:

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), "是");
	 }
}
}

3.在应用中加入测试用例:


		import flexunit.framework.TestSuite;
		private  function onCreateComplete():void {
			var ts:TestSuite = new TestSuite();
			ts.addTest(new TestSimpleConverter("testSimpleConverter"));
			testRunner.test = ts;
			testRunner.startTest();
		}

4.截图:

image

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.