Introduction
ASMock ("Ay-Es-Mock" or "Az-Mock") is a dynamic mocking framework for ActionScript 3 (Flex and Flash). ASMock allows you to create fake versions of dependant components (classes and interfaces) so that your unit tests do not end up testing multiple components. Being a dynamic mocking framework means you don't have to do anything to create the mock, the framework creates the object for you at runtime.
Latest news
ASMock 0.9 has been released, with some significant updates:
- FlexUnit 4 now supported (as default)
- Dynamic mocks and stubs now supported
- Property stubbing (automatic properties) now supported
- FlexUnit 1 and fluint 1 integration are now distributed as SWCs
- Rest and optional arguments now supported on constructors
- Expectation error messages are now much clearer (though there's still some work to do in this area)
On top of all that, there's a brand new project wiki that includes a whole new quick start guide and integration examples with all the major testing frameworks.
ASMock 0.9 is getting closer to release with support for stubs, dynamic mocks, stubbed properties and FlexUnit 4. Integration with FlexUnit 4 is a bit cleaner as it is done entirely through metadata (no base class):
[Mock("mx.graphics.IStroke")]
[RunWith("asmock.flexunit.ASMockClassRunner")]
public class SampleFixture
{
[Test]
public function testWeightStub() : void
{
var mocker : MockRepository = new MockRepository();
var stroke : IStroke = IStroke(mocker.createStub(IStroke));
stroke.replay();
stroke.weight = 5;
assertThat(stroke.weight, equals(5));
}
}
Update (2009-23-01): Re-released beta 1 due to an issue with Adobe AIR