开始用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
- package {
-
- import flexunit.framework.TestCase;
-
- public class BankAccountTest extends TestCase {
-
- /**
- * Test Deposit
- */
- public function testDeposit():void {
- var bankAccount:BankAccount=new BankAccount();
- bankAccount.deposit(50);
- assertTrue("Balance on a new account after 50 deposit is 50", bankAccount.getBalance() == 50);
- bankAccount.deposit(25);
- assertEquals("Balance after 50 deposit and another 25 deposit is 75", 75,bankAccount.getBalance());
-
- }
-
- /**
- * Test withdraw
- */
- public function testWithdraw():void {
- var bankAccount:BankAccount=new BankAccount();
- bankAccount.deposit(100);
- bankAccount.withdraw(50);
- assertTrue("Balance on a new account after 100 deposit and a 50 withdraw is 50", bankAccount.getBalance() == 50);
-
-
- }
-
- }
|