androidx.test.espresso.intent.Intents.internalIntended(org.hamcrest.Matcher, androidx.test.espresso.intent.VerificationMode, java.util.List)' on a null object reference
espresso로 UI 테스트를 하다가 저런 문구를 가진 에러가 났다.
onView(withId(R.id.rv_main_list))
.perform(RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(0 , click()))
intended(toPackage("패키지 명")) //<- 이곳에서
그 이유는 이렇게 ActivityTestRule을 사용했기 때문이다.
@Rule @JvmField
var mMainActivity = ActivityTestRule(MainActivity::class.java)
IntentsTestRule을 사용해야지 intended, intending 같은 메소드를 사용할 수 있다.
@Rule @JvmField
var mMainActivity = IntentsTestRule(MainActivity::class.java)
그런데 ActivityTestRule과 IntentTestRule이 무엇이 다른지 궁금해져서 검색해보았다.
What is the difference between ActivityTestRule and IntentTestRule
while exploring Testing I came across ActivityTestRule and IntentTestRule as far as i have understood is this that IntentTestRule are an extension of ActivityTestRule and are used in Espresso Inten...
stackoverflow.com
IntentTestRule를 사용하면 @Test 어노테이션이 달린 각 테스트 전에 자동으로 Espresso-Intents를 초기화 하고 각 테스트가 끝난 이후 Espresso-Intents를 해제합니다.
@Override
protected void afterActivityLaunched() {
Intents.init();
super.afterActivityLaunched();
}
@Override
protected void afterActivityFinished() {
super.afterActivityFinished();
Intents.release();
}
ActivityTestRule을 IntentTestRule 대신 사용할 수 있으나
@Before 및 @After에 각각 Intents.init () 및 Intents.release ()를 수동으로 호출해야한다.
또한 Espresso-intents란
테스트중인 응용 프로그램에서 보낸 인 텐트의 유효성 검사 및 스텁을 활성화한다. Mockito와 비슷하지만 Android 인 텐트 용이다.
그러니 테스트에서 intent가 포함된 테스트를 하기 위해서는 IntentTestRule을 사용하면 되고 필요가 없는 테스트라면 ActivityTestRule을 사용하면 된다.