[Android] Espresso를 사용한 UI 테스트가 실행되지 않는 이슈

Minji Jeong·2023년 6월 30일
0

Troubleshooting

목록 보기
20/20
post-thumbnail

🟡 Test Case

  • 안드로이드 스튜디오에서 Espresso를 사용해 UI 테스트 시도
  • build.gradle에 다음과 같이 dependencies 추가 (3.5.1 -> Latest Version)

build.gradle

참고 : Android Test Dependencies
// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'

// Core library
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' 
// Espresso Dependency for RecyclerView
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.5.1' 
  • 추가 후, 작성한 테스트 코드를 실행했으나 아래와 같이 테스트가 수행되지 않고 계속 멈춰있음

🔴 Root Cause

StackOverFlow: Espresso tests not running in android studio

위 글을 참고해보니, Espresso 최신 버전에 문제가 있는 듯 했다. core와 contrib의 버전을 모두 낮춰야 한다는 답변도 있지만, 실제로 테스트 해보니 core 최신 버전을 사용했을 떄는 문제가 없었다. 결론적으로는 contrib 최신 버전에서만 문제가 발생하는 듯 했다 (현재 회사에서 contrib을 사용하여 RecyclerView 테스트를 하고있기 때문에 contrib에 대한 의존성을 지울 수는 없었다).

위 글에 따라 최신 버전인 3.5.1 에서 3.3.0으로 다운그레이드 한 후, 테스트 코드를 다시 실행했다.

androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.3.0' 

버전을 낮추니 실행은 되었지만, 이번엔 테스트가 실행 도중 취소되는 에러가 발생하였다.

StackOverFlow : Espresso UI Test Cancelled with no error message


위 글에 대한 답변을 보니, 특정 버전의 에뮬레이터에서 위 문제가 발생하는 것 같았다. 약간 납득이 안되는 버그라 좀 당황스럽다(Espresso가 좀 버그가 많은 라이브러리 인걸까?ㅎ) 내가 실행중이던 에뮬레이터는 API 레벨 32였는데, 이 에뮬레이터를 종료하고 API 30 에뮬레이터를 실행했다.

내 테스트 코드는 모종의 이유로 실패했으나, 어쨌든 제대로 실행은 되었다. 왜 Espresso contrib 최신 버전에서만 저런 버그가 발생하고 있므며, 특정 레벨 이상의 에뮬레이터에서는 왜 테스트가 취소되는지 의문이다.

build.gradle

androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.3.0'
profile
Mobile Software Engineer

0개의 댓글