I am currently struggling to implement a functional test in Android ListActivity, which implements LoaderManager.LoaderCallbacks. This operation has a simple layout that has an EditText for the user to enter some string, and a ListView that populates through the Custom CursorAdapter, which retrieves data from the custom content provider and uses the LoadManager to automatically update the contents of the list when it changes.
The expected functionality of this ListActivity is intended only so that the User can enter some stings in EditText and select one or more items from the ListView.
To achieve this functional test, I use Expresso, and here comes 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, then the trace of the error stack that 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 as I used in other functional tests of my application, which worked fine, which made me think that the problem could be related to the initialization of the test, since the only difference for other tests is that this activity uses the CursorAdapter and Loadmanager
If someone needs more contextualization, ask. Thanks:)
source share