Android 安卓意式浓缩咖啡

Android 安卓意式浓缩咖啡,android,android-intent,intentfilter,android-espresso,Android,Android Intent,Intentfilter,Android Espresso,我的测试文件如下所示: @RunWith(AndroidJUnit4.class) @LargeTest public class CreateNewSessionActivityTest { @Rule public IntentsTestRule<CreateNewSessionActivity> mActivityRule = new IntentsTestRule<>(CreateNewSessionActivity.class); @T

我的测试文件如下所示:

@RunWith(AndroidJUnit4.class)
@LargeTest
public class CreateNewSessionActivityTest {
    @Rule
    public IntentsTestRule<CreateNewSessionActivity> mActivityRule = new IntentsTestRule<>(CreateNewSessionActivity.class);

    @Test
    public void test() {
        final Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, "this is my auth token");

        final Instrumentation.ActivityResult result = new Instrumentation.ActivityResult(Activity.RESULT_OK, intent);

        intending(hasComponent(hasShortClassName(".CreateNewSessionActivity"))).respondWith(result);

        onView(withId(R.id.create_new_session_auth_token_edit_text)).check(matches(isDisplayed()));
        onView(withId(R.id.create_new_session_auth_token_edit_text)).check(matches(withText("this is my auth token")));
    }
}
我还在活动下面的清单中注册了意图过滤器

<intent-filter>
    <action android:name="android.intent.action.SEND"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:mimeType="text/plain"/>
</intent-filter>

文本根本不会显示在编辑文本中。我想测试意图的方式有什么问题吗?

意图
用于测试输出意图。要测试传入意图,请使用
ActivityRule
,第三个参数为
false

@Rule
public ActivityTestRule activityRule = new ActivityTestRule<>(
    CreateNewSessionActivity.class,
    true,    // initialTouchMode
    false);  // launchActivity. False to set intent.

有关更多信息,请参阅。

非常感谢!一个不相关的问题。如果满足某些条件,我会在应用程序启动时显示一个对话框。该对话框未通过测试。因为对话框位于我要测试的视图上方。如何指定
create\u new\u session\u auth\u token\u edit\u text
的父/根是什么?请发布其他问题如果有人对
@Rule
有错误,请将其更改为
@get:Rule
。大多数情况下,它可以解决错误。
onView(withId(R.id.create_new_session_auth_token_edit_text)).check(matches(withText("this is my auth token")));
@Rule
public ActivityTestRule activityRule = new ActivityTestRule<>(
    CreateNewSessionActivity.class,
    true,    // initialTouchMode
    false);  // launchActivity. False to set intent.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "this is my auth token");
activityRule.launchActivity(intent);