-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1.2.0/AN-Refactor, Feat] PokemonList toolbar collapse 애니메이션 테스트 #474
Conversation
cad53f0
to
8f0fea7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
흠 잡을 곳이 없군요!~~ 고생했습니다!!! 💯
override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback?) { | ||
this.callback = callback | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
우와 진짜 이거 어케 찾았어요..? 💯
동작 원리
- Flow 에서 새로운 값이 방출될 때마다
idleCondition
로 idle 여부를 판단 idleCondition
이 true를 반환하면,isIdle
을 true로 설정하고 Espresso의callback?.onTransitionToIdle()
을 호출해 idle 상태를 알림.- 이 이후로는 에스프레소 프레임워크가 알아서 작업이 완료된 것으로 간주하고 테스트를 진행.
이게 맞죠?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 테스팅 모듈로 빼볼 수 있나 생각해봤는데 그러면 모듈 간의 순환참조가 일어나는 군요.
참 어렵네요.
예니, 꼬상은 좋은 생각 있으신가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ㅋㅋㅋㄱㅋ 저도 이생각을 했답니당
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
일요일까지 여행이라서.. 🥲 다녀와서 바로 볼게요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 정도는 ,,, 뭐 ,,, 나뿌지 않다고 봅니당 ㅎㅅㅎ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고하셨습니다 !!! 늦어져서 미안해용 🥲
@@ -24,10 +34,41 @@ class PokemonListActivityTest { | |||
testViewModelModule, | |||
) | |||
|
|||
@Before | |||
fun setUp() { | |||
ShadowLooper.runUiThreadTasksIncludingDelayedTasks() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
대박대박...역시 오둥..😮
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메시지 큐에 작업들을 동기적으로 처리... 메모 🗒️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 정도는 ,,, 뭐 ,,, 나뿌지 않다고 봅니당 ㅎㅅㅎ
- 비동기 작업이 완료되었는지 감지해 Espresso 테스트실행 흐름 제어
8f0fea7
to
8a0b960
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리뷰가 많이 늦었네요.. 미안합니다🙏🏻
역시 테스트는 어렵네요
val viewModel = activity.getViewModel<PokemonListViewModel>() | ||
|
||
// StateFlow의 값이 비어 있지 않은 상태를 Idle로 간주 | ||
idlingResource = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IdlingResource를 사용해서 Espresso에게 알려줄 수 있군요.. 대박신기
@@ -24,10 +34,41 @@ class PokemonListActivityTest { | |||
testViewModelModule, | |||
) | |||
|
|||
@Before | |||
fun setUp() { | |||
ShadowLooper.runUiThreadTasksIncludingDelayedTasks() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메시지 큐에 작업들을 동기적으로 처리... 메모 🗒️
작업한 내용
:testing
모듈에 분리:testing
모듈에 분리PR 포인트
Flow debounce api 때문에 테스트 못하던 문제 해결
Flow 의 debounce api 때문에
300ms
이전까지는 empty View를 보여지게됩니다.그래서,
300ms
가 완전히 지나고 나서 테스트하라고 espresso 한테 알려주어야 테스트할 수 있습니다.즉, 비동기 작업이 모두 완료가 된 이후에 ui test가 진행하도록 동기화를 해주어야합니다.
Robolectric, android Test 각각 다른 방법으로 이를 맞추었습니다.
1. Robolectric Test
ShadowLooper.runUiThreadTasksIncludingDelayedTasks() api 를 활용했습니다.
Robolectric 을 활용하면 ShadowLooper 가 안드로이드 MainThread Looper를 shadowing합니다. 따라서,
ShadowLooper.runUiThreadTasksIncludingDelayedTasks()
를 통해MainThread 의 MessageQueue 에 등록되어 있는 메세지들을 모두 실행한 후, 테스트를 실행하라는 것을 보장해주었습니다.
2. Espresso Test
Espresso 는 MainThread 나 AsyncTask 에서 작업한 작업들은 알아서 동기 처리해주지만,
Debounce
와 같은 외부 api는 동기 처리해주지 않습니다. 이럴 때,IdlingResource api 를 활용하면 됩니다.
쉽게 말해서 동기 처리해줘야할 작업을
IdlingResource
에 정의해두고IdlingRegistry
에 등록만 해주면 됩니다! 저희는Flow
로 비동기 작업을 처리하기 때문에FlowIdlingResource
와asIdlingResource()
함수를 작성해두었습니다추가 수정한 부분
WeatherSpinner
에 package 경로가 없어서 테스트가 통과 못하더라구요! 그래서 추가했습니다.🚀Next Feature