1 Android Mock 2 3 Copyright 2010 Google Inc. 4 All Rights Reserved. 5 Author: swoodward (a] google.com (Stephen Woodward) 6 7 8 Android Mock is a wrapper for EasyMock (2.4) which allows for real Class mocking on 9 an Android (Dalvik) VM. 10 11 All methods on Android Mock are syntactically equivalent to EasyMock method 12 calls, and will delegate calls to EasyMock, while performing the required 13 transformations to avoid Dalvik VM troubles. 14 15 Calls directly to EasyMock will work correctly only if the Class being mocked 16 is in fact an Interface. Calls to Android Mock will work correctly for both 17 Interfaces and concrete Classes. 18 19 Android Mock requires that the code being mocked be instrumented prior to 20 loading to the Dalvik VM by having called the MockGenerator.jar file. Try 21 running java -jar MockGenerator.jar --help for more information. 22 23 An example usage pattern is: 24 25 @UsesMocks(MyClass.class) 26 public 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