NPE in Fresco.initialize(this) in the Application when running Robolectric Unit Test
See original GitHub issueWe use GitHub Issues for bugs.
If you have a non-bug question, please ask on Stack Overflow: http://stackoverflow.com/questions/tagged/fresco
— Please use this template, and delete everything above this line before submitting your issue —
Description
Im trying to run a unit test using Robolectric ( testImplementation “org.robolectric:robolectric:3.7.1”) and a NPE appears when executing Fresco.initialize(this) in the main Application. This is the code of the test:
@RunWith(RobolectricTestRunner.class)
public class MainActivityTest {
@Test
public void testRecyclerData() {
final MainActivity activity = Robolectric.setupActivity(MainActivity.class);
final RecyclerView recyclerView = activity.findViewById(R.id.recycler_view_main_activity);
final List<Show> list = new ArrayList<Show>();
list.add(new Show());
activity.addDataToView(list);
Assert.assertEquals(1, recyclerView.getAdapter().getItemCount());
}
}
Here is the stack:
java.lang.NullPointerException
at java.io.File.<init>(File.java:277)
at com.facebook.soloader.SoLoader.initImpl(SoLoader.java:198)
at com.facebook.soloader.SoLoader.init(SoLoader.java:120)
at com.facebook.soloader.SoLoader.init(SoLoader.java:104)
at com.facebook.drawee.backends.pipeline.Fresco.initialize(Fresco.java:63)
at com.facebook.drawee.backends.pipeline.Fresco.initialize(Fresco.java:39)
at com.sebas.sysfishapp.videofeed.MainApplication.onCreate(MainApplication.java:16)
at org.robolectric.android.internal.ParallelUniverse.lambda$setUpApplicationState$0(ParallelUniverse.java:204)
at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:72)
at org.robolectric.android.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:203)
at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:333)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:245)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:130)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:42)
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:84)
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.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.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.$Proxy3.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
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.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.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:748)
Reproduction
100%
Solution
[OPTIONAL: Do you know what needs to be done to address this issue? Ideally, provide a pull request which fixes this issue.]
Additional Information
- Fresco version:1.8.1
- Platform version: API 21
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Robolectric with ActiveAndroid setup nullpointerexception on ...
If I run the unit test with a custom Application class where ActiveAndroid.initialize(this); where is not being called my unit tests run (only...
Read more >NPE in ShadowApplication.registerBroadcastReceivers
Hi I'm new to Android development (Java web and unit testing background) and trying to get Robolectric 3.0-rc3 working on a rather sizable...
Read more >Bountysource
NPE in Fresco.initialize(this) in the Application when running Robolectric Unit Test.
Read more >Using Robolectric for Android unit testing on the JVM - Tutorial
To use Robolectric for your Android unit tests, add the following dependency to your Gradle build file. ... Your tests should be stored...
Read more >Android Notes for Professionals - Pratama Nur Wijaya Blog
Section 3.23: Use gradle.properties for central versionnumber/ ... Chapter 80: Unit testing in Android with JUnit ... Section 86.5: Initializing a font.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@foghina @BeforeClass is working thanks. and the method should be static in the TestClass
Confirmed that
works for me.