Issue
I have an issue when attempting to execute espresso tests for a non launcher activity. The problem I'm experiencing is that on the first test, the launcher activity gets launched instead of the activity under test.
Here is my code:
@MediumTest
@RunWith(AndroidJUnit4.class)
public class MyActivityTest extends BaseRobot {
@Rule
public ActivityTestRule<MyActivity> mActivityRule = new ActivityTestRule<>(MyActivity.class);
@Test
public void testManifestListVisible() throws Exception {
allOf(withId(R.id.llContainer), isDisplayed());
}
@Test
public void testManifestBtnVisible() throws Exception {
isViewDisplayed(R.id.btManageManifest);
}
@Test
public void testManifestBtn() throws Exception {
clickButton(R.id.btManageManifest);
}
When the first test gets executed I get this error:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id:com.xxx.xxx:id/myBtnId
This error occurs because the launcher activity is being launched for the first test(I'm certain of this because I can see it on the device). For the other tests MyActivity is launched as expected.
Note: I'm using this version of the libs
espressoVersion = '3.0.1'
hamcrestVersion = '1.3'
supportAnnotationsVersion = '23.1.0'
testRunnerVersion = '1.0.1'
testRulesVersion = '1.0.1'
Thank you in advance!
Solution
Found a work around for anyone who has the same issue. Before the tests add a method that manually launches the intent. Here is an example:
public class InstrumentationActivityTest {
@Rule
public ActivityTestRule<InstrumentationActivity> mActivityRule = new
ActivityTestRule<>(InstrumentationActivity.class);
@Before
public void startIntentManually() {
mActivityRule.launchActivity(new Intent());
}
//add tests
Don't know if this is the best solution, but it works.
Answered By - android enthusiast
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.