A few questions with the Robolectric test and ActionBarActivity

I will just start by setting up the project (as far as I understand, this is relevant for the current problem):

Android studio 0.8.6

Gradle 1.12

robolectric- gradle -plugin 0.11.0

robolectric 2.3 (also tested with 2.4-SNAPSHOT)

com.android.support:support-v4 20.0.0

com.android.support:appcompat-v7 20.0.0

com.google.android.gms: play-services 5.2.08

I have an activity that extends the ActionBarActivity that I want to test. First edition:

If I use the following setting, I get a NullPointerException from Robolectric when trying to read AndroidManifest:

@Config(emulateSdk = 18, manifest = "src/main/AndroidManifest.xml")
@RunWith(RobolectricTestRunner.class)
public class FilterActivityTest {}

This error occurs when trying to read a value for:

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

, https://github.com/robolectric/robolectric/issues/1025 https://github.com/robolectric/robolectric-gradle-plugin/issues/56. , . @Config :

@Config(manifest = "build/intermediates/manifests/debug/AndroidManifest.xml", resourceDir = "../../../../build/intermediates/res/debug", emulateSdk = 18)

:

android.content.res.Resources$NotFoundException: Resource ID #0x7f0c0000
    at android.content.res.Resources.getValue(Resources.java:1118)
    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2304)
    at android.content.res.Resources.getLayout(Resources.java:934)
    at android.support.v7.internal.view.SupportMenuInflater.inflate(SupportMenuInflater.java:115)
    at ro.cursurideschimb.user.FilterActivity.onCreateOptionsMenu(FilterActivity.java:56)
    at android.app.Activity.onCreatePanelMenu(Activity.java:2504)
    at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:225)
    at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:233)
    at android.support.v7.app.ActionBarActivityDelegateICS.onCreatePanelMenu(ActionBarActivityDelegateICS.java:146)
    at android.support.v7.app.ActionBarActivity.onCreatePanelMenu(ActionBarActivity.java:200)
    at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onCreatePanelMenu(ActionBarActivityDelegateICS.java:293)
    at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:413)
    at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:775)
    at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:198)
    at org.robolectric.util.Scheduler.postDelayed(Scheduler.java:37)
    at org.robolectric.shadows.ShadowLooper.post(ShadowLooper.java:207)
    at org.robolectric.shadows.ShadowHandler.postDelayed(ShadowHandler.java:56)
    at android.os.Handler.postDelayed(Handler.java)
    at android.view.ViewRootImpl$RunQueue.executeActions(ViewRootImpl.java:6230)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1239)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
    at android.view.Choreographer.doFrame(Choreographer.java:532)
    at android.view.Choreographer$FrameHandler.handleMessage(Choreographer.java:664)
    at org.robolectric.shadows.ShadowHandler.routeMessage(ShadowHandler.java:125)
    at org.robolectric.shadows.ShadowHandler.access$100(ShadowHandler.java:25)
    at org.robolectric.shadows.ShadowHandler$1.run(ShadowHandler.java:110)
    at org.robolectric.util.Scheduler$PostedRunnable.run(Scheduler.java:162)
    at org.robolectric.util.Scheduler.runOneTask(Scheduler.java:107)
    at org.robolectric.util.Scheduler.advanceTo(Scheduler.java:92)
    at org.robolectric.util.Scheduler.advanceToLastPostedRunnable(Scheduler.java:68)
    at org.robolectric.util.Scheduler.unPause(Scheduler.java:25)
    at org.robolectric.shadows.ShadowLooper.unPause(ShadowLooper.java:228)
    at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:267)
    at org.robolectric.util.ActivityController.create(ActivityController.java:110)
    at org.robolectric.util.ActivityController.create(ActivityController.java:120)
    at ro.cursurideschimb.user.FilterActivityTest.setUp(FilterActivityTest.java:30)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:267)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:194)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

= "v10" @Config.

:

java.lang.NullPointerException
at android.support.v7.app.ActionBarImplICS.setDisplayHomeAsUpEnabled(ActionBarImplICS.java:179)
at android.support.v7.app.ActionBarImplJB.setDisplayHomeAsUpEnabled(ActionBarImplJB.java:20)
at ro.cursurideschimb.user.FilterActivity.initialize(FilterActivity.java:72)
at ro.cursurideschimb.user.FilterActivity.onCreate(FilterActivity.java:105)
at android.app.Activity.performCreate(Activity.java:5133)
at org.fest.reflect.method.Invoker.invoke(Invoker.java:112)
at org.robolectric.util.ActivityController$1.run(ActivityController.java:113)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:265)
at org.robolectric.util.ActivityController.create(ActivityController.java:110)
at org.robolectric.util.ActivityController.create(ActivityController.java:120)
at ro.cursurideschimb.user.FilterActivityTest.setUp(FilterActivityTest.java:30)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:267)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:194)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

(Line 72 in FilterActivity reads like this:  actionBar.setDisplayHomeAsUpEnabled(true);)

, reportSdk = 10 @Config, .

. .

+4

All Articles