Skip to content
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

Merged
merged 13 commits into from
Dec 13, 2024

Conversation

murjune
Copy link
Contributor

@murjune murjune commented Dec 1, 2024

작업한 내용

  • RecyclerView 관련 Espresso util 함수들 :testing 모듈에 분리
  • testContext :testing 모듈에 분리
  • PokeList collapse 애니메이션 Robolectric 테스트
  • PokeList collapse 애니메이션 Espresso 테스트

PR 포인트

Flow debounce api 때문에 테스트 못하던 문제 해결

image

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 에 등록되어 있는 메세지들을 모두 실행한 후, 테스트를 실행하라는 것을 보장해주었습니다.

image

2. Espresso Test

Espresso 는 MainThread 나 AsyncTask 에서 작업한 작업들은 알아서 동기 처리해주지만, Debounce 와 같은 외부 api는 동기 처리해주지 않습니다. 이럴 때,
IdlingResource api 를 활용하면 됩니다.

쉽게 말해서 동기 처리해줘야할 작업을 IdlingResource 에 정의해두고 IdlingRegistry에 등록만 해주면 됩니다! 저희는 Flow로 비동기 작업을 처리하기 때문에 FlowIdlingResourceasIdlingResource() 함수를 작성해두었습니다

image

추가 수정한 부분

  • WeatherSpinner 에 package 경로가 없어서 테스트가 통과 못하더라구요! 그래서 추가했습니다.

🚀Next Feature

  • Fragment 테스트 문제있던거 고칠듯?

@github-actions github-actions bot added AN_FEAT ✨ 안드 새로운 기능 AN_REFACTOR ✍️ 안드로이드 리팩토링 v1.2.0 🏷️ labels Dec 1, 2024
@murjune murjune force-pushed the an/feat/android-tool-bar-test branch 2 times, most recently from cad53f0 to 8f0fea7 Compare December 1, 2024 17:05
Copy link
Contributor

@sh1mj1 sh1mj1 left a 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
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

우와 진짜 이거 어케 찾았어요..? 💯

동작 원리

  1. Flow 에서 새로운 값이 방출될 때마다 idleCondition로 idle 여부를 판단
  2. idleCondition이 true를 반환하면, isIdle을 true로 설정하고 Espresso의 callback?.onTransitionToIdle()을 호출해 idle 상태를 알림.
  3. 이 이후로는 에스프레소 프레임워크가 알아서 작업이 완료된 것으로 간주하고 테스트를 진행.

이게 맞죠?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 테스팅 모듈로 빼볼 수 있나 생각해봤는데 그러면 모듈 간의 순환참조가 일어나는 군요.
참 어렵네요.
예니, 꼬상은 좋은 생각 있으신가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ㅋㅋㅋㄱㅋ 저도 이생각을 했답니당

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일요일까지 여행이라서.. 🥲 다녀와서 바로 볼게요

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 정도는 ,,, 뭐 ,,, 나뿌지 않다고 봅니당 ㅎㅅㅎ

Copy link
Contributor

@JoYehyun99 JoYehyun99 left a 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

대박대박...역시 오둥..😮

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메시지 큐에 작업들을 동기적으로 처리... 메모 🗒️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 정도는 ,,, 뭐 ,,, 나뿌지 않다고 봅니당 ㅎㅅㅎ

@murjune murjune force-pushed the an/feat/android-tool-bar-test branch from 8f0fea7 to 8a0b960 Compare December 11, 2024 17:27
Copy link
Contributor

@kkosang kkosang left a 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 =
Copy link
Contributor

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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메시지 큐에 작업들을 동기적으로 처리... 메모 🗒️

@murjune murjune merged commit a289e42 into an/develop Dec 13, 2024
2 checks passed
@murjune murjune deleted the an/feat/android-tool-bar-test branch December 13, 2024 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AN_FEAT ✨ 안드 새로운 기능 AN_REFACTOR ✍️ 안드로이드 리팩토링 v1.2.0 🏷️
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants