Espresso Test Failed: 1 intention is required, Actually corresponds to 2 intentions

I get this error when starting activity start using espresso.

android.support.test.espresso.base.DefaultFailureHandler $ AssertionFailedWithCauseError: 1 intent required. Actually corresponds to 2 intentions.

Surprisingly, other launch launch tests with the same code are passed.

@RunWith(AndroidJUnit4.class) public class HomeActivityTest { @Rule public final IntentsTestRule<HomeActivity> mHomeActivityRule = new IntentsTestRule<HomeActivity>(HomeActivity.class); @Test public void testFundTransferActivityStarted() { onView(withId(R.id.button_fund_transfer)).perform(click()); intended(hasComponent("mypackage.FundTransferActivity")); } } 
Button

just starts FundTransfer activity using startActivity.

+6
source share
1 answer

Could you insert the full error message you received?

The error message will also have a configuration of 2 Intents. If both of these intentions have the same configuration, this means that you call startActivity twice, that is, between the start of the test and the end of the test. Below is the answer for a specific case when you call the same Intent twice.

A challenge twice is a perfectly legitimate case. For instance,

Step 1 : press Button1 to launch the Gallery, and select the image and show it in ImageView1 (initially ImageView1 is GONE , but now it is VISIBLE ).
Step 2 : Click ImageView1 to start the gallery again.

Now, if you want to test β€œClicking on ImageView1 should launch theβ€œ Gallery ”, you cannot just click on ImageView1 , since it does not appear at the initial stage. You need to press Button1 first. If you do this, you need to launch the gallery twice .

Therefore, intended(hasComponent("mypackage.FundTransferActivity")); will not work. Instead use: intended(hasComponent("mypackage.FundTransferActivity"), times(2));

+8
source

All Articles