Reputation: 51
I am currently struggling implementing a functional test on an Android ListActivity that implements a LoaderManager.LoaderCallbacks. This Activity has a simple layout that has an EditText for the user to enter some string, and a ListView that is populated via a Custom CursorAdapter that fetch the data from a Custom Content Provider, and uses the LoadManager to automatically update the list view content when it changes.
The expected functionallity of this ListActivity is only for a User to enter some sting on to the EditText and to select one or more items from the ListView.
To achieve this functional test, I'm using Expresso, and here goes my implementation:
public class NewWordActivityFunctionalTest extends ActivityInstrumentationTestCase2<NewWordActivity>{
public NewWordActivityFunctionalTest() {
super(NewWordActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
getActivity();
}
public void testFillNewThemeFormAndSubmit() throws InterruptedException {
onView(withId(R.id.submit_new_word_button))
.perform(click());
}
}
If I run it, the error stack trace I get is the following:
com.google.android.apps.common.testing.ui.espresso.NoActivityResumedException: No activities in stage RESUMED. Did you forget to launch the activity. (test.getActivity() or similar)?
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:579)
at com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:69)
at com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:40)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:159)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.doPerform(ViewInteraction.java:90)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.perform(ViewInteraction.java:73)
at pt.consipere.hangman.ui.test.NewWordActivityFunctionalTest.testFillNewThemeFormAndSubmit(NewWordActivityFunctionalTest.java:36)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onStart(GoogleInstrumentationTestRunner.java:167)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
This test setup is the same I have used in other functional tests of my app that worked perfectly fine, which made me think that the problem may be with the test initialization since the only difference for the other tests is the fact that this activity is using a CursorAdapter and the LoadManager.
If anyone needs more contextualization please ask. Thank you :)
Upvotes: 5
Views: 4745