浓咖啡检查意图是否正确

时间:2018-12-17 21:29:40

标签: android android-intent android-espresso

我正在尝试检查意图是否正确接收了以下代码传递的参数:

@RunWith(AndroidJUnit4.class)
public class ResultActivityTest
{

    private static final int WEEK_TO_BE_TYPED = 40;
    private static final String PACKAGE_NAME = "edu.uoc.android.currentweek";

    @Rule
    public IntentsTestRule<MainActivity> mIntentsRule = new IntentsTestRule<>(MainActivity.class);

    @Test
    public void SendText_checkText()
    {
        // Type text and then press the button.
        onView(withId(R.id.main_ed_week_number)).perform(typeText(Integer.toString(WEEK_TO_BE_TYPED)), closeSoftKeyboard());
        onView(withId(R.id.main_btn_check)).perform(click());

        // Check that the text was sent correctly.
        intended(allOf(hasComponent(ResultActivity.class.getName()), toPackage(PACKAGE_NAME), hasExtra(ResultActivity.EXTRA_WEEK, WEEK_TO_BE_TYPED)));
    }

}

当我尝试执行此测试时出现问题,它引发了以下错误:

  

测试运行失败:由于“过程”,仪表运行失败   崩溃了。”

build.gradle上有以下内容:

defaultConfig {
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
}

我缺少什么?

0 个答案:

没有答案