FlexUnit4

前些日子试用了FlexUnit4,发现真的非常的不错,非常的简单,省去了很多的麻烦。现在补个例子,加深理解。

首先你要在你的库中添加FlexUnit4.swc & FlexUnit4UIListener.swc,这两个文件你可以到

http://www.flexunit.org/ 下载。

现在建立一个要测试的类

package commond
{
	public class SimpleMath
	{
		public function add(n1:Number,n2:Number):Number
		{
			return n1 + n2;
		}
		
		public function divide(n1:Number,n2:Number):Number
		{
			if(n2 == 0)
			{
				throw new TypeError("sdfdasdfasd");
			}
			return n1/n2;
		}
	}
}

 然后建立一个测试类

package unit
{
	import commond.SimpleMath;
	
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.soap.WebService;
	
	import org.flexunit.Assert;

	public class SimpleMathTest
	{
		private static var simpleMath:SimpleMath;
		[BeforeClass]
		public static function init():void
		{
			simpleMath = new SimpleMath();
		}
		
		[AfterClass]    
		public static function runAfterClass():void {     
			// run for one time after all test cases     
		}
		
		[Test]
		public function add():void
		{
			Assert.assertEquals(12,simpleMath.add(1,11));
		}
		
		[Test(expects="TypeError")]
		public function divide():void
		{
			simpleMath.divide(10,0);
		}
		[Ignore("Not Ready to Run")]
		[Test(description="Maybe it's wright")]
		public function add2():void
		{
			Assert.assertEquals(12,simpleMath.add(1,1111));
		}
		[Test(async="true")]
		public function asny():void
		{
			var webService:WebService = new WebService();
			webService.wsdl = "http://feeds.adobe.com/webservices/mxna2.cfc?wsdl";
			webService.addEventListener(FaultEvent.FAULT,onFalut);
			webService.addEventListener(ResultEvent.RESULT,onResult);
			webService.loadWSDL();
			webService.getCategories();
		}
		
		private function onFalut(event:FaultEvent):void
		{
			trace("onFalut");
		}
		
		private function onResult(event:ResultEvent):void
		{
			trace("onResult");
		}
		
		
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值