Skip to content Skip to sidebar Skip to footer

Espresso Activitytestrule For Activity With Generic Type Parameter

I have declared an activity like this class QuestionnaireActivity : AppCompatActivity() I want to write an espresso test so I'm writting ActivityTestRule l

Solution 1:

similar to here the solution involves defining an inline function like this

inlinefun<reified T: Activity>activityTestRuleWithIntent(intent: Intent) =  object : ActivityTestRule<T>(T::class.java){
    overridefungetActivityIntent(): Intent = intent
}

then the rule becomes:

@Rule@JvmField
val rule = activityTestRuleWithIntent<QuestionnaireActivity<ProfileModel.LifeStyleInfo>>(QuestionnaireActivity.getQuestionnaireIntent(InstrumentationRegistry.getTargetContext(), 3, ProfileModel.LifeStyleInfo()))

Post a Comment for "Espresso Activitytestrule For Activity With Generic Type Parameter"