[今天,我开始使用Espresso
测试Activity
,我在Junit
测试中很实际,但不了解如何模拟,当我尝试执行以下操作时,我有CashPeriod这行显然给了我一个NPE
使用Espresso启动活动
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//no layout preview possible
setContentView(R.layout.activity_combi_book_balance)
title = getString(R.string.balance_details)
setupActionBarWithHomeEnabled(true)
val cashPeriod: CashPeriod = intent.extras.getParcelable(PERIOD_OBJECT_EXTRA)
val sections = showList(cashPeriod)
setAdapter(sections)
}
我的浓缩咖啡测试是
@Test
fun appLaunchesSuccessfully() {
ActivityScenario.launch(CombiBookBalanceDetailActivity::class.java)
}
现在,如果我在onCreate中存入CashPeriod并给出一些硬编码的值,则测试会通过,但我当然需要在测试类中进行此操作
[[我该如何在意式浓缩咖啡测试中模拟val cashPeriod行:CashPeriod = intent.extras.getParcelable(PERIOD_OBJECT_EXTRA)? Junit有所不同,在Junit中,我使用Mockito / mockito-kotlin / mockk并给出行为when /// return //that
ActivityTestRule
参见this