我有一个活动,在单击按钮时会启动一个外部活动。外部活动是根据操作启动的,活动名称及其包名称未知。我尝试使用Espresso来模拟这种意图,但这种方法不起作用,并且测试失败。
MyActivity.java
@Override
public void onCreate(final Bundle savedInstanceState) {
mLaunchButton = (Button) findViewById(R.id.launch_button);
mLaunchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
Log.i(TAG, "Launch button clicked.");
startActivity(new Intent("action_string"));
}
});
}
MyActivityTest.java
@Rule
public IntentsTestRule<MyActivity> mIntentRule =
new IntentsTestRule<>(MyActivity.class);
@Test
public void testActivity() {
onView(withId(R.id.launch_button)).perform(click());
intended(hasAction("action_string"));
}
错误
android.support.test.espresso.PerformException: Error performing 'single click - At Coordinates: 391, 715 and precision: 16, 16' on view 'with id: com.domain.myapp:id/launch_button'.
.
.
.
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=action_string (has extras) }
.
.
.