I know there are plenty of post about roboelectric and gradle, but I could not set it up for my project.
Let's start with the situation.
My project has three buildtypes that use diferent package name for each. I'm using some SDK that require to use the package name in the manifest, so to solve this I'm using a key in the manifest and then in each buildType I use this
manifestPlaceholders = [_MY_PACKAGENAME_: getName()]
So I configure roboelectirc as it's said with the guide for gradle, but I can't make it work. I try diferent things such as the plugin Android Unit Test and with all the solutions I'm getting different errors.
Like java.lang.NoSuchMethodError cannot be cast to java.lang.RuntimeException
Anyone can help me with this?
Test example code:
@Config(emulateSdk = 18)
@RunWith(RobolectricTestRunner.class)
public class RoboElectricVerifyTest {
@Test
public void simpleTest() throws Exception {
final Context context = Robolectric.getShadowApplication().getApplicationContext();
System.out.println("Package name is: " + context.getPackageName());
Activity activity = Robolectric.buildActivity(MainActivity.class).create().get();
assertThat(activity != null);
}
}
And this is the output
WARNING: no system properties value for ro.build.date.utc
DEBUG: Loading resources for com.package.name from /Users/path_to_project/app/build/test-resources/Debug/res...
WARNING: no system properties value for gsm.sim.operator.alpha
Unexpected HTTP call POST https://07f605c7.api.splkmobile.com/1.0/07f605c7/0/0/1?hash=none HTTP/1.1
DEBUG: Loading resources for android from jar:/Users/marcel/.m2/repository/org/robolectric/android-all/4.3_r2-robolectric-0/android-all-4.3_r2-robolectric-0.jar!/res...
java.lang.ClassCastException: java.lang.NoSuchMethodError cannot be cast to java.lang.RuntimeException
at org.robolectric.internal.ReflectionHelpers.callInstanceMethodReflectively(ReflectionHelpers.java:68)
at org.robolectric.util.ActivityController$1.run(ActivityController.java:115)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:268)
at org.robolectric.util.ActivityController.create(ActivityController.java:111)
at org.robolectric.util.ActivityController.create(ActivityController.java:122)
at package.RoboElectricVerifyTest.simpleTest(RoboElectricVerifyTest.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:236)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:158)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Process finished with exit code 255