1Android Mock 2 3Copyright 2010 Google Inc. 4All Rights Reserved. 5Author: swoodward@google.com (Stephen Woodward) 6 7 8Android Mock is a wrapper for EasyMock (2.4) which allows for real Class mocking on 9an Android (Dalvik) VM. 10 11All methods on Android Mock are syntactically equivalent to EasyMock method 12calls, and will delegate calls to EasyMock, while performing the required 13transformations to avoid Dalvik VM troubles. 14 15Calls directly to EasyMock will work correctly only if the Class being mocked 16is in fact an Interface. Calls to Android Mock will work correctly for both 17Interfaces and concrete Classes. 18 19Android Mock requires that the code being mocked be instrumented prior to 20loading to the Dalvik VM by having called the MockGenerator.jar file. Try 21running java -jar MockGenerator.jar --help for more information. 22 23An example usage pattern is: 24 25@UsesMocks(MyClass.class) 26public void testFoo() MyClass { 27 mockObject = AndroidMock.createMock(MyClass.class); 28 AndroidMock.expect(mockObject.foo(0)).andReturn(42); 29 AndroidMock.replay(mockObject); assertEquals(42, mockObject.foo(0)); 30 AndroidMock.verify(mockObject); 31} 32 33