I have a class with a regular method and my own method that I would like to make fun of:
public class MyClass { public int regularMethod() { ... } public void native myNativeMethod(); }
I use Robolectric to test my application, and I am trying to find a way to mock these methods using a custom shadow class . Here is my shadow class:
@Implements(MyClass.class) public class MyShadowClass { @Implementation public int regularMethod { return 0; } @Implementation public void nativeMethod { ... } }
Here is my test:
@RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE) public class MyTest { @Test @Config(shadows = { MyShadowClass.class }) public void test() { MyClass obj = new MyClass(); Assert.assertEquals(obj.regularMethod(), 0); } }
This does not work as I thought. Mocking your own method can be extended with the Shadow class, but I thought that using a custom shadow class this way would cause the shadow class code to be called.
class mocking shadow robolectric
dliu120
source share