Android studio 浓缩咖啡测试设置变量

Android studio 浓缩咖啡测试设置变量,android-studio,testing,automated-tests,android-espresso,Android Studio,Testing,Automated Tests,Android Espresso,是否可以从正在运行浓缩咖啡测试的活动中设置变量?因为当我试图设置一个变量时,比如: activityRule.getActivity().mViewPager.setCurrentItem(1); 我得到一个错误: lStateException: Must be called from main thread of fragment host 您可以这样做: @get:Rule val intentsTestRule = ActivityTestRule(MainActivity::cla

是否可以从正在运行浓缩咖啡测试的活动中设置变量?因为当我试图设置一个变量时,比如:

activityRule.getActivity().mViewPager.setCurrentItem(1);
我得到一个错误:

lStateException: Must be called from main thread of fragment host

您可以这样做:

@get:Rule
val intentsTestRule = ActivityTestRule(MainActivity::class.java, false, true)

@Before
fun start {
   val intent = Intent().apply {
      putExtra("value", 1)
   }

   intentsTestRule.launchActivity(intent)
}
然后在活动中:

if (intent.getIntExtra("value", 0)) {
    //Do you stuff
}