关闭

用FlexUnit做单元测试

发表于:2010-2-08 13:51

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:wangzhen(网易博客)    来源:51Testing软件测试网采编

  开始用FlexUnit单元测试

  前提:1.下载FlexUnit,该工程包含类库

  2.创建单元测试 Unit tests

  3.创建测试集 Test suite 4.创建Test runner

  下载FlexUnitLibrary:http://code.google.com/p/as3flexunitlib,解压会找到flexunit.swc。

  添加该类库到你的工程中。

  创建单元测试:

  A unit test is made up of  logical assertions.If an assertion is true, the unit test passes. If an assertion is false then the unit test fails.

  There are several assertion methods available for our unit tests such as: assertTrue, assertFalse, assertNull, assertEquals, and several others.

  BankAccountTest.as

  1. package {   
  2.      
  3.     import flexunit.framework.TestCase;   
  4.        
  5.     public class BankAccountTest extends TestCase {   
  6.                        
  7.             /**  
  8.              * Test Deposit  
  9.              */  
  10.             public function testDeposit():void {   
  11.             var bankAccount:BankAccount=new BankAccount();   
  12.             bankAccount.deposit(50);   
  13.             assertTrue("Balance on a new account after 50 deposit is 50", bankAccount.getBalance() == 50);   
  14.             bankAccount.deposit(25);   
  15.             assertEquals("Balance after 50 deposit and another 25 deposit is 75", 75,bankAccount.getBalance());   
  16.                    
  17.             }   
  18.                
  19.             /**  
  20.              * Test withdraw  
  21.              */  
  22.             public function testWithdraw():void {   
  23.             var bankAccount:BankAccount=new BankAccount();   
  24.             bankAccount.deposit(100);   
  25.             bankAccount.withdraw(50);   
  26.             assertTrue("Balance on a new account after 100 deposit and a 50 withdraw is 50", bankAccount.getBalance() == 50);   
  27.                
  28.       
  29.             }   
  30.                
  31.         }   

32/3<123>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号