Friday, September 11, 2009

Mock samples for AS3

I have uploaded the mock samples for AS3 (FlexUnit and mock4as1.0) at the MockSampels project.

The samples are concise and illustrative examples of Mock Objects features, such as exceptions, consecutive calls, and time-based testing.

Bellow are some snapshots of the test code.

sample code from the BankSysteTest



accountFrom.expects("withdraw").withArg(20.0).willThrow(new InsufficientFundsException());
try{
bank.transfer(accountFrom, accountTo, 20.0);
}catch (e:InsufficientFundsException){
assertNotNull(e);
}
accountFrom.verify();

sample code rom the TimedCacheTest



cache = new TimedCache(objectLoader, clock, reloadPolicy);
objectLoader.expects("load").times(1).withArg(KEY).willReturn(VALUE);
assertEquals(VALUE, cache.lookUp(KEY));
objectLoader.verify();