我有一个用于 UI 测试的 Espresso 测试套件,如下所示:
@RunWith(AndroidJUnit4.class)
public class SpecialUiTests {
@Rule
public final ActivityTestRule<SpecialActivity> activity
= new ActivityTestRule<>(SpecialActivity.class);
@Test
public void specialTest() {
...
}
...
}
问题是,该活动需要一个捆绑包,并且在找不到它期望的值时崩溃
public class SpecialActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
final String specialValue = getIntent().getBundleExtra(ARG_SPECIAL_BUNDLE)
.getString(KEY_SPECIAL_VALUE);
//Do something with specialValue <--- Crash
}
...
}
我可以设置测试规则并仍然传递活动期望的参数(捆绑包)吗?