在android中,我有一个包含2个Activity,MainActivity和DetailsActivity的示例应用程序。在主活动中,有一个列表和一个按钮,通过按下它可以打开详细信息活动。在意图中,我放了一个ArrayList和一个Object。
我如何测试它是否有效?浓咖啡好吗?
androidTestCompile 'com.android.support:support-annotations:25.3.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
@RunWith(AndroidJUnit4.class)
@LargeTest
public class FirstTest {
@Rule
public IntentsTestRule<MainActivity> mActivityRule = new IntentsTestRule<>(
MainActivity.class);
@Test
public void changeText_sameActivity() {
onView(withId(R.id.fab)).perform(click());
// How can i Specify the intent to the new Detail Activity?
intended(hasComponent(new ComponentName(getTargetContext(), InsectDetailsActivity.class)));
onView(withId(R.id.tv_original_title))
.check(matches(withText( /* The text depends on the Passing Intent*/)));
}
}
答案 0 :(得分:1)
重复的问题。见here。以下是该问题的答案:
intended(hasComponent(new ComponentName(getTargetContext(),ExpectedActivity.class)))