Robolectric test fails when ProgressBar is added (sdk 26) - android

I'm facing issue with running robolectric test cases with sdk 26. Test are running fine, but when I add a ProgressBar to the respective layout, all test cases for that fragment (which contains the progress bar layout) starts to fail.
Also if I change that sdk to 25 using #Config, test is passing even with ProgressBar in the layout.
Robolectric version used:
testCompile 'org.robolectric:robolectric:3.4.2'
testCompile 'org.robolectric:shadows-multidex:3.3.2'
testCompile 'org.robolectric:shadows-support-v4:3.3.2'
Android Support libraries : 26
Please find below the log for the failure issue:
android.view.InflateException: XML file build/intermediates/data-binding-layout-out/AppFrameworkHamburger/debug/layout/fragment_insights.xml line #-1 (sorry, not yet implemented): XML file build/intermediates/data-binding-layout-out/AppFrameworkHamburger/debug/layout/fragment_insights.xml line #-1 (sorry, not yet implemented): Error inflating class android.widget.ProgressBar
Caused by: android.view.InflateException: XML file build/intermediates/data-binding-layout-out/AppFrameworkHamburger/debug/layout/fragment_insights.xml line #-1 (sorry, not yet implemented): Error inflating class android.widget.ProgressBar
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.$$robo$$createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createView(LayoutInflater.java)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.onCreateView(CalligraphyLayoutInflater.java:164)
at android.view.LayoutInflater.$$robo$$onCreateView(LayoutInflater.java:720)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.onCreateView(CalligraphyLayoutInflater.java:148)
at android.view.LayoutInflater.$$robo$$createViewFromTag(LayoutInflater.java:788)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflate(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java)
at android.view.LayoutInflater.$$robo$$inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
at android.view.LayoutInflater.$$robo$$inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java)
at com.philips.platform.appframework.connectivitypowersleep.insights.InsightsFragment.onCreateView(InsightsFragment.java:73)
at android.support.v4.app.Fragment.$$robo$$performCreateView(Fragment.java:2343)
at android.support.v4.app.Fragment.performCreateView(Fragment.java)
at android.support.v4.app.FragmentManagerImpl.$$robo$$moveToState(FragmentManager.java:1419)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java)
at android.support.v4.app.FragmentManagerImpl.$$robo$$moveFragmentToExpectedState(FragmentManager.java:1740)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java)
at android.support.v4.app.FragmentManagerImpl.$$robo$$moveToState(FragmentManager.java:1809)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java)
at android.support.v4.app.BackStackRecord.$$robo$$executeOps(BackStackRecord.java:799)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java)
at android.support.v4.app.FragmentManagerImpl.$$robo$$executeOps(FragmentManager.java:2580)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java)
at android.support.v4.app.FragmentManagerImpl.$$robo$$executeOpsTogether(FragmentManager.java:2367)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java)
at android.support.v4.app.FragmentManagerImpl.$$robo$$removeRedundantOperationsAndExecute(FragmentManager.java:2322)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java)
at android.support.v4.app.FragmentManagerImpl.$$robo$$execPendingActions(FragmentManager.java:2229)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java)
at android.support.v4.app.FragmentManagerImpl$1.$$robo$$run(FragmentManager.java:700)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java)
at android.os.Handler.$$robo$$handleCallback(Handler.java:789)
at android.os.Handler.handleCallback(Handler.java)
at android.os.Handler.$$robo$$dispatchMessage(Handler.java:98)
at android.os.Handler.dispatchMessage(Handler.java)
at org.robolectric.shadows.ShadowMessageQueue.dispatchMessage(ShadowMessageQueue.java:164)
at org.robolectric.shadows.ShadowMessageQueue.access$100(ShadowMessageQueue.java:31)
at org.robolectric.shadows.ShadowMessageQueue$1.run(ShadowMessageQueue.java:138)
at org.robolectric.util.Scheduler.runOrQueueRunnable(Scheduler.java:317)
at org.robolectric.util.Scheduler.postDelayed(Scheduler.java:154)
at org.robolectric.util.Scheduler.postDelayed(Scheduler.java:143)
at org.robolectric.shadows.ShadowMessageQueue.enqueueMessage(ShadowMessageQueue.java:145)
at android.os.MessageQueue.enqueueMessage(MessageQueue.java)
at android.os.Handler.$$robo$$enqueueMessage(Handler.java:661)
at android.os.Handler.enqueueMessage(Handler.java)
at android.os.Handler.$$robo$$sendMessageAtTime(Handler.java:630)
at android.os.Handler.sendMessageAtTime(Handler.java)
at android.os.Handler.$$robo$$sendMessageDelayed(Handler.java:600)
at android.os.Handler.sendMessageDelayed(Handler.java)
at android.os.Handler.$$robo$$post(Handler.java:356)
at android.os.Handler.post(Handler.java)
at android.support.v4.app.FragmentManagerImpl.$$robo$$scheduleCommit(FragmentManager.java:2098)
at android.support.v4.app.FragmentManagerImpl.scheduleCommit(FragmentManager.java)
at android.support.v4.app.FragmentManagerImpl.$$robo$$enqueueAction(FragmentManager.java:2081)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java)
at android.support.v4.app.BackStackRecord.$$robo$$commitInternal(BackStackRecord.java:680)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java)
at android.support.v4.app.BackStackRecord.$$robo$$commit(BackStackRecord.java:634)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java)
at com.philips.platform.appframework.connectivitypowersleep.insights.InsightsFragmentTest.setUp(InsightsFragmentTest.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
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.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.mockito.internal.junit.JUnitRule$1.evaluate(JUnitRule.java:16)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:228)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:110)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:37)
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.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:64)
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:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: android.content.res.Resources$NotFoundException: null
Caused by: android.content.res.Resources$NotFoundException: File jar:/Users/philips/.m2/repository/org/robolectric/android-all/o-preview-4-robolectric-0/android-all-o-preview-4-robolectric-0.jar!/res/drawable/progress_medium_material.xml from drawable resource ID #0x108091c
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:769)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:600)
at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:232)
at org.robolectric.internal.bytecode.ShadowImpl.directlyOn(ShadowImpl.java:59)
at org.robolectric.shadow.api.Shadow.directlyOn(Shadow.java:57)
at org.robolectric.shadows.ShadowResourcesImpl.loadDrawable(ShadowResourcesImpl.java:238)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java)
at android.content.res.Resources.loadDrawable(Resources.java:885)
at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:953)
at android.content.res.TypedArray.getDrawable(TypedArray.java:928)
at android.widget.ProgressBar.__constructor__(ProgressBar.java:281)
at android.widget.ProgressBar.<init>(ProgressBar.java)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.onCreateView(CalligraphyLayoutInflater.java:164)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.onCreateView(CalligraphyLayoutInflater.java:148)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.philips.platform.appframework.connectivitypowersleep.insights.InsightsFragment.onCreateView(InsightsFragment.java:73)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2343)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:700)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at org.robolectric.shadows.ShadowMessageQueue.dispatchMessage(ShadowMessageQueue.java:164)
at org.robolectric.shadows.ShadowMessageQueue.access$100(ShadowMessageQueue.java:31)
at org.robolectric.shadows.ShadowMessageQueue$1.run(ShadowMessageQueue.java:138)
at org.robolectric.util.Scheduler.runOrQueueRunnable(Scheduler.java:317)
at org.robolectric.util.Scheduler.postDelayed(Scheduler.java:154)
at org.robolectric.util.Scheduler.postDelayed(Scheduler.java:143)
at org.robolectric.shadows.ShadowMessageQueue.enqueueMessage(ShadowMessageQueue.java:145)
at android.os.MessageQueue.enqueueMessage(MessageQueue.java)
at android.os.Handler.enqueueMessage(Handler.java:661)
at android.os.Handler.sendMessageAtTime(Handler.java:630)
at android.os.Handler.sendMessageDelayed(Handler.java:600)
at android.os.Handler.post(Handler.java:356)
at android.support.v4.app.FragmentManagerImpl.scheduleCommit(FragmentManager.java:2098)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:2081)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:680)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:634)
at com.philips.platform.appframework.connectivitypowersleep.insights.InsightsFragmentTest.setUp(InsightsFragmentTest.java:66)
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.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.mockito.internal.junit.JUnitRule$1.evaluate(JUnitRule.java:16)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:228)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:110)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:37)
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.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:64)
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:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Related

java.lang.IllegalStateException: No view holder at position: 1

Clicking a recycler view list item (with Espresso UI automation test) on a medium size phone works fine
onView(withId(R.id.rv_recycler_view))
.perform(actionOnItemAtPosition(i, click()));
But with tablet the above code results in an error I don't understand
android.support.test.espresso.PerformException: Error performing 'android.support.test.espresso.contrib.RecyclerViewActions$ActionOnItemAtPositionViewAction#b575cb0' on view 'with id: com.example.michael.bakingapp:id/rv_recycler_view'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:80)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56)
at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184)
at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115)
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87)
at com.example.michael.bakingapp.MainActivityTest.foo(MainActivityTest.java:35)
at java.lang.reflect.Method.invoke(Native Method)
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 android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1932)
Caused by: java.lang.IllegalStateException: No view holder at position: 1
at android.support.test.espresso.contrib.RecyclerViewActions$ActionOnItemAtPositionViewAction.perform(RecyclerViewActions.java:290)
at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction.java:144)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:159)
at android.app.ActivityThread.main(ActivityThread.java:6097)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
edit
Now I see some crucial bit of info from stack-trace, but still does not resolve why this error occurs on tablet only
caused by: java.lang.IllegalStateException: No view holder at position: 1
Call check before perform action.
onView(withId(R.id.rv_recycler_view)).check(ViewAssertions.matches(isDisplayed()));
onView(withId(R.id.rv_recycler_view))
.perform(actionOnItemAtPosition(i, click()));

Robolectric tests failing when run on CLI

Tests are running fine in Android Studio, but not when I run them on the CLI with Gradle. I am guessing something with the classpath. Here is the stacktrace. Any ideas?
I get the same results with robolectric 3.3.2 or 3.4-rc1 and 3.4-rc1
java.lang.RuntimeException: java.lang.NullPointerException
at
org.robolectric.res.ResourceTableFactory.parseResourceFiles
(ResourceTableFactory.java:155)
at
org.robolectric.res.ResourceTableFactory.newResourceTable
(ResourceTableFactory.java:43)
at org.robolectric.res.ResourceMerger.buildResourceTable
(ResourceMerger.java:22)
at org.robolectric.RobolectricTestRunner.getAppResourceTable
(RobolectricTestRunner.java:450)
at org.robolectric.RobolectricTestRunner.beforeTest
(RobolectricTestRunner.java:288)
at org.robolectric.internal.SandboxTestRunner$2.evaluate
(SandboxTestRunner.java:203)
at org.robolectric.internal.SandboxTestRunner.runChild
(SandboxTestRunner.java:109)
at org.robolectric.internal.SandboxTestRunner.runChild
(SandboxTestRunner.java:36)
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.internal.SandboxTestRunner$1.evaluate
(SandboxTestRunner.java:63)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at
org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter
.runTestClass(JUnitTestClassExecuter.java:114)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter
.execute(JUnitTestClassExecuter.java:57)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor
.processTestClass(JUnitTestClassProcessor.java:66)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor
.processTestClass(SuiteTestClassProcessor.java:51)
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch
(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch
(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch
(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter
$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy1.processTestClass(Unknown Source)
at
org.gradle.api.internal.tasks.testing.worker.TestWorker
.processTestClass(TestWorker.java:109)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch
(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch
(ReflectionDispatch.java:24)
at
org.gradle.internal.remote.internal.hub
.MessageHubBackedObjectConnection
$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:146)
at org.gradle.internal.remote.internal.hub.
MessageHubBackedObjectConnection$DispatchWrapper.dispatch
(MessageHubBackedObjectConnection.java:128)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run
(MessageHub.java:404)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures
.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run
(StoppableExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker
(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:617)
at org.gradle.internal.concurrent.ThreadFactoryImpl
$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at org.robolectric.res.DocumentLoader.loadFile(DocumentLoader.java:35)
at org.robolectric.res.DocumentLoader.load(DocumentLoader.java:26)
at org.robolectric.res.ResourceTableFactory.parseResourceFiles
(ResourceTableFactory.java:140)
... 41 more

How to test search view result?

Test steps:
Input text to search
Test that input text is displayed in list
My test:
private static final String TEST_SURNAME = "AnySurname";
private static final String TEST_NAME = "AnyName";
private static final String TEST_FULL_NAME = TEST_SURNAME + " " + TEST_NAME;
#Test
public void searchTestPerson() {
onView(withId(R.id.searchView)).perform(click());
onView(withId(android.support.design.R.id.search_src_text)).perform(typeText(TEST_FULL_NAME));
onData(allOf(withRowString(Person.SURNAME_COLUMN_NAME, TEST_SURNAME), withRowString(Person.NAME_COLUMN_NAME, TEST_NAME)))
.check(matches(isDisplayed()));
}
The text successfully inserts in search view, but on last step (onData()) it's failing with this error:
android.support.test.espresso.PerformException: Error performing 'load adapter data' on view 'is assignable from class: class android.widget.AdapterView'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:80)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56)
at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184)
at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115)
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87)
at android.support.test.espresso.DataInteraction.load(DataInteraction.java:151)
at android.support.test.espresso.DataInteraction.check(DataInteraction.java:141)
at com.my_project.android.fragment.PersonFragmentTest.searchTestPerson(PersonFragmentTest.java:125)
at java.lang.reflect.Method.invoke(Native Method)
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.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1879)
Caused by: java.lang.RuntimeException: No data found matching: (Rows with column: is "Surname"with String is "AnySurname" and Rows with column: is "Name" with String is "AnyName") contained values: <[]>
at android.support.test.espresso.action.AdapterDataLoaderAction.perform(AdapterDataLoaderAction.java:96)
at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction.java:144)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Tests ran to completion.

Perform Exception on recycler view item (Espresso)

So I'm trying to do a click on a RecyclerView item. If the position is in the view then this code works fine
onView(withId(R.id.recyclerView)).perform(
RecyclerViewActions.actionOnItemAtPosition(7, click()));
So say if the item is not in the view I first perform a scroll action and then I click on it. Which is unnecessary in the case because RecyclerViewActions.actionOnItemAtPosition originally calls
new ScrollToPositionViewAction(position).perform(uiController, view);
uiController.loopMainThreadUntilIdle();
Before performing actual click operation. Reference
Anyways, in the end, it's producing this following exception
android.support.test.espresso.PerformException: Error performing 'single click' on view 'with id: com.abc.test.d:id/recyclerView'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:70)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:53)
at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184)
at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115)
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87)
at com.abc.test.FirstScreenTest.testInteraction(FirstScreenTest.java:69)
at java.lang.reflect.Method.invoke(Native Method)
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.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:257)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:54)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:240)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1879)
Caused by: android.support.test.espresso.PerformException: Error performing 'click (after 3 attempts)' on view 'unknown'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83)
at android.support.test.espresso.action.MotionEvents.sendDown(MotionEvents.java:111)
at android.support.test.espresso.action.Tap.sendSingleTap(Tap.java:133)
at android.support.test.espresso.action.Tap.access$100(Tap.java:35)
at android.support.test.espresso.action.Tap$1.sendTap(Tap.java:40)
at android.support.test.espresso.action.GeneralClickAction.perform(GeneralClickAction.java:98)
at android.support.test.espresso.contrib.RecyclerViewActions$ActionOnItemAtPositionViewAction.perform(RecyclerViewActions.java:303)
at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction.java:144)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Cannot instantiate OrmLite helper in a unit test class in Android Studio

This is my code:
#RunWith(MockitoJUnitRunner.class)
public class OrmLiteTest {
OrmLiteDatabaseHelper databaseHelper;
#Mock
Context mMockContext;
#Before
public void setup() {
mMockContext = Mockito.mock(Context.class);
databaseHelper = OpenHelperManager.getHelper(mMockContext,
OrmLiteDatabaseHelper.class);
}
I get the following exception when I run the test:
java.lang.IllegalStateException: Could not construct instance of helper class class com.example.myapp.application.OrmLiteDatabaseHelper
at com.j256.ormlite.android.apptools.OpenHelperManager.constructHelper(OpenHelperManager.java:222)
at com.j256.ormlite.android.apptools.OpenHelperManager.loadHelper(OpenHelperManager.java:170)
at com.j256.ormlite.android.apptools.OpenHelperManager.getHelper(OpenHelperManager.java:78)
at com.bulatsa.despark.OrmLiteTest.setup(OrmLiteTest.java:39)
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.RunBefores.evaluate(RunBefores.java:24)
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.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
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:140)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.j256.ormlite.android.apptools.OpenHelperManager.constructHelper(OpenHelperManager.java:220)
... 31 more
Caused by: java.lang.NullPointerException
at com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper.openFileId(OrmLiteSqliteOpenHelper.java:310)
at com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper.<init>(OrmLiteSqliteOpenHelper.java:76)
at com.bulatsa.despark.application.OrmLiteDatabaseHelper.<init>(OrmLiteDatabaseHelper.java:28)
... 36 more
You are trying to invoke a method (or similar) on an object which is null in the OrmLiteSqliteOpenHelper.java, line 310
As you didn't share that code, that's all we can say...
Caused by: java.lang.NullPointerException
at com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper.openFileId(OrmLiteSqliteOpenHelper.java:310)
Oh, and the line...
mMockContext = Mockito.mock(Context.class);
...should be removed, since the #RunWith(MockitoJUnitRunner.class) will already inject a mock there, no need to create one manually.

Categories

Resources