I am Jiahao, creator of the second repository you are talking about.
First of all, thanks for checking the code. I do a lot of research on Android, and I am glad that my research is useful for someone else.
Then, Shadow of Robolectric. I use Robolectric 3.1 in this project to check how Robolectric 3 works with MarshMallow: https://github.com/jiahaoliuliu/robolectricForMarshmallow
I tested the new runtime permission manager, as well as the shadow application and actions.
Here is a sample shadow activity code:
import android.content.Context; import com.jiahaoliuliu.robolectricformarshmallow.controller.MainController; import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; @Implements(MainController.class) public class MainControllerShadow { public void __constructor__ (Context context) {
https://github.com/jiahaoliuliu/robolectricForMarshmallow/blob/master/app/src/test/java/com/jiahaoliuliu/robolectricformarshmallow/shadow/MainControllerShadow.java
And this is how I use it in unit test:
package com.jiahaoliuliu.robolectricformarshmallow;
import com.jiahaoliuliu.robolectricformarshmallow.shadow.MainControllerShadow; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; import org.robolectric.RobolectricGradleTestRunner; import org.robolectric.annotation.Config; import static org.junit.Assert.*; @RunWith(RobolectricGradleTestRunner.class) @Config(constants = BuildConfig.class, manifest = Config.NONE, application = FoolApplication.class, shadows = { MainControllerShadow.class}, sdk = 18) public class MainActivityTest { private MainActivity mMainActivity; @Before public void setUp() throws Exception { mMainActivity = Robolectric.setupActivity(MainActivity.class); } @After public void tearDown() throws Exception { } @Test public void testOnCreate() throws Exception {
https://github.com/jiahaoliuliu/robolectricForMarshmallow/blob/master/app/src/test/java/com/jiahaoliuliu/robolectricformarshmallow/MainActivityTest.java
As you can see, I am not using the configured Gradle Test Runner. I checked the source code of Robolectric, for versions 3.0 and 3.1 (the latter) it is enough to simply specify the shadow classes in the header.
I hope this helps
jiahao
source share