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

Step1 미션 제출합니다 #2

Open
wants to merge 9 commits into
base: stopkite
Choose a base branch
from

Conversation

stopkite
Copy link

@stopkite stopkite commented Feb 6, 2023

로컬에 해당 유저가 있는지 혹은 없는지 두 가지 테스트로 경우를 나눈 이유는
로컬에 유저 존재 유무에 따라 localSource와 remoteResource가 나뉘어 호출되기 때문입니다.
그래서 '유저가 있는지'만 테스트를 하려다가 이 둘을 명확하게 구분하기 위해 두 가지 경우를 나누어서 테스트를 진행하였습니다.
다만 뭔가 true, false값으로 존재한다/안한다를 Boolean으로 명확히 표시하고 싶었는데 이 부분이 잘 안된 것 같습니다.

유저가 존재하지 않는 경우 remote 관련해서 저장하는 테스트를 해보려다가 저장된 값을 어디서 가져와야할 지 감이 안잡혀서
그냥 서버로부터 전달받은 expectedGithubProfile라는 값이 잘 들어왔나를 확인하는 테스트를 진행하였습니다.

Copy link
Member

@malibinYun malibinYun left a comment

Choose a reason for hiding this comment

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

1단계 미션 고생 많으셨어요~!
모킹 테스트가 어색하고 이상해서 작성하기 어려우셨을 것 같아요 🥲

코멘트 남겨 주신 것에 대해서는 리뷰에 녹여서 잘 풀어써봤어요. 더 궁금한 게 있으시면 더 질문해주세요!!
피드백 반영하시고 다시 리뷰 요청 부탁드릴게요!!

Comment on lines +21 to +25
companion object {
@JvmStatic
@RegisterExtension
val instantTaskExecutorExtension = InstantTaskExecutorExtension()
}
Copy link
Member

Choose a reason for hiding this comment

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

이 extension은 안드로이드 요소 (LiveData) 등이 끼어있는 유닛테스트를 할 때 추가해주시면 돼요!

Comment on lines +35 to +39
// given
val expectedName = "stopkite"

coEvery { fakeLocalSource.getGithubProfile("stopkite").getOrThrow().userName } returns "stopkite"

Copy link
Member

Choose a reason for hiding this comment

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

.getGithubProfile()이 반환하는 것이 GithubProfile 객체이기에, 이 객체를 모두 하드코딩으로 직접 만들어주는 것이 바람직해요!

모킹은 작성해주신 것 처럼 체이닝을 길게 써도 가능은 하지만, 원하는 객체가 기대하는 값을 반환하게 적는 게 가장 좋아요 :)

Comment on lines +47 to +48
@Test
fun `로컬에 유저 정보가 없음을 확인할 수 있다`() = runBlocking {
Copy link
Member

Choose a reason for hiding this comment

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

Repository에서는 로컬에 유저정보가 있는 지 없는 지에 대한 정보를 외부에 알리지 않고 있어요.
내부적으로만 활용하고 있기 때문에 이 Repository에 대한 테스트라고 보기엔 어려워요.

getGithubProfile을 할 때 repository에서 무슨 일이 벌어지고 있는 지 테스트해보는 것은 어떨까요?

Comment on lines +61 to +74
@Test
fun `로컬에 유저 정보가 이미 존재할 때 유저 정보를 반환할 수 있다`() = runBlocking {
// given
val githubProfile = GithubProfile(
0,
"stopkite",
"https://avatars.githubusercontent.com/u/62979643?v=4",
"Ji-Yeon",
"1",
10,
100
)

coEvery { fakeLocalSource.getGithubProfile("stopkite") } returns runCatching { githubProfile }
Copy link
Member

Choose a reason for hiding this comment

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

remote source의 메서드는 정말로 호출하지 않았는 지 테스트해보는 것도 좋겠네요 :)

Comment on lines +76 to +77
// when
val actualLocalProfile = fakeLocalSource.getGithubProfile("stopkite").getOrThrow()
Copy link
Member

Choose a reason for hiding this comment

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

getOrThrow를 하면 정말로 throw가 발생할 수도 있기 때문에, (test fail)
getOrNull을 활용해보는 것은 어떨까요?
assertThat()에 들어가는 타입은 null이어도 괜찮아요 :)

Comment on lines +83 to +85
@Test
fun `유저 정보가 없을 때 서버로부터 유저 정보를 받아오는 것을 확인할 수 있다`() = runBlocking {
// given
Copy link
Member

Choose a reason for hiding this comment

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

getGithubProfile을 할 때 유저 정보가 없음을 Repository는 무엇을 통해 알았는지 한 번 생각해보면 좋겠어요 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants