I have updated my test cases dependencies from this to this(as given below in code snippet ), since then I am facing this error of java.lang.NullPointerException: Cannot run onActivity since Activity has been destroyed already . while earlier this test case was working fine.
But Now its not wokring, giving error at line scenarioRule.getScenario().onActivity(activity -> {
// this
testImplementation 'org.robolectric:robolectric:4.5-beta-1'
testImplementation 'androidx.test.espresso:espresso-core:3.4.0'
testImplementation 'androidx.test.espresso:espresso-contrib:3.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
// to this
testImplementation 'org.robolectric:robolectric:4.14.1'
testImplementation 'androidx.test.espresso:espresso-core:3.6.1'
testImplementation 'androidx.test.espresso:espresso-contrib:3.6.1'
androidTestImplementation 'androidx.test:rules:1.6.1'
@RunWith(AndroidJUnit4.class)
public class NfcCardReaderActivityTest {
@Rule
public ActivityScenarioRule<NfcCardReaderActivity> scenarioRule
= new ActivityScenarioRule<>(NfcCardReaderActivity.class);
@Test
public void testHelperIsShown() {
scenarioRule.getScenario().onActivity(activity -> {
activity.onResume();
checkHasText(
activity,
R.id.info_text,
R.string.helper_description
);
});
}