In meinem Testfacebook Screenshot-Tests-for-android thow Nullpointer auf Make-Screenshot
@LargeTest
@RunWith(AndroidJUnit4.class)
public class SimpleActicityTest {
@Rule
public ActivityTestRule<MainActivity> activityActivityTestRule =
new ActivityTestRule<>(MainActivity.class);
@Test
public void testActivity() throws Exception {
Activity a = activityActivityTestRule.getActivity();
Screenshot.snapActivity(activity).setName("s1").record();
}
Ich habe
ava.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.app.Instrumentation.getContext()' on a null object reference
at com.facebook.testing.screenshot.internal.ScreenshotImpl.getInstance(ScreenshotImpl.java:338)
at com.facebook.testing.screenshot.Screenshot.snapActivity(Screenshot.java:45)
at com.mobium.reference.activity.Util.takeScreenshot(Util.java:32)
at com.mobium.reference.activity.SimpleActicityTest.lambda$testLeftMenuTest$1(SimpleActicityTest.java:52)
at com.mobium.reference.activity.SimpleActicityTest.access$lambda$0(SimpleActicityTest.java)
at com.mobium.reference.activity.SimpleActicityTest$$Lambda$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5549)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)
Quelle lib getInstance des faceebook():
public static ScreenshotImpl getInstance() {
if(sInstance != null) {
return sInstance;
} else {
Class var0 = ScreenshotImpl.class;
synchronized(ScreenshotImpl.class) {
if(sInstance != null) {
return sInstance;
} else {
Instrumentation instrumentation = Registry.getRegistry().instrumentation;
Bundle arguments = Registry.getRegistry().arguments;
HostFileSender hostFileSender = new HostFileSender(instrumentation, arguments);
sInstance = create(instrumentation.getContext(), arguments, hostFileSender);
return sInstance;
}
}
}
}
Es erstellt Registrierung und öffentliche Feldinstrumentierung, aber es gibt keine Instrumentierungsinitialisierungen im Registrierungskonstruktor. Wie kann es funktionieren?