`
luhantu
  • 浏览: 199809 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

FlexUnit4

    博客分类:
  • Flex
 
阅读更多

前些日子试用了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");
		}
		
		
	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics