I'm having trouble using espresso to check for activity that starts using intent. The thread of work works as follows
- In the main operation, you press the button
- Button launches AsyncTask to get some data
- onPostExecute of AsyncTask, I create the intention to add the data received as Intent Extra, and then start a new action that displays the extracted data.
The code that creates the intent and launches the new action is as follows:
@Override protected void onPostExecute(String result) { Intent intent = new Intent(context, NewActivity.class); intent.putExtra(key, result); context.startActivity(intent); }
It all works when I run the application. As for testing using espresso, the test code is as follows:
... @Rule public IntentsTestRule<MainActivity> mIntentTestRule = new IntentsTestRule<>(MainActivity.class, false); @Test public void testMainActivityAsyncTask() { // Find view with button onView(withText(R.string.button_text)).perform(click()); // Ensure correct intent setup intended(allOf( hasComponent(NewActivity.class.getName()), hasExtraWithKey(key), toPackage("com.example.espresso"))); // Ensure appropriate activity and view is launched onView( allOf(withId(R.id.expected_view), withText(isEmptyOrNullString()))); // Let it go Intents.release(); }
When I run the test, the test fails with these errors (briefly for brevity):
... It is required to fulfill 1 intention. Actually corresponds to 0 intentions.
Agreed intentions: []
Recorded intentions: -Intent {cmp = com.example.doingstuff / com.example.espresso.NewActivity (has additional)} processing packages: [[com.example.doingstuff]], additional functions: [Bundle [{akey = aVal] ])
A few questions are here: 1. Why does the cmp value in the error message precede the package name of my MainActivity ie class "com.example.doingstuff /", which may be part of my problem 2. Is the above error message suggesting that it detected an intention , that is, "com.example.doingstuff / com.example.espresso.NewActivity", but it did not match what was expected?
I did a lot without googling searches. Any help is appreciated.