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

[#20] 단위테스트 #22

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

Conversation

hsgo2430
Copy link
Contributor

@hsgo2430 hsgo2430 commented Jun 7, 2024

👻 이슈

이슈 포함할 때, - #[이슈번호] 해주세요.

✍️ 공부 내용 적어주세요.

  • 코드가 잘 작동하는지 테스트하는 방법을 공부했습니다.
  • 코드랩에서 3개의 코드 선택후 테스트 코드를 작성해보았습니다.

🦖 이슈가 있었다면 적어주세요.

main 브랜치에다가 전부 파니까 버전 카탈로그 공부한것도 올라가버리네요... 이건 제가 어떻게든 수정하겠습니다
일단은 버전카탈로그 코드 삭제하고 올립니다.

👀 참조 레퍼런스

[Local Unit Test] https://zrr.kr/SZl2
[Instrumented Unit Test]https://zrr.kr/ew4L
[Android Unit Tests(단위 테스트)]https://jepark-diary.tistory.com/19

@hsgo2430 hsgo2430 added 🔥 PR PR 올립니다~ 🍏 안드로이드 Android Skill 😶‍🌫️ 미흡 숨어야지.. labels Jun 7, 2024
@hsgo2430 hsgo2430 self-assigned this Jun 7, 2024
@Jokwanhee
Copy link
Contributor

main 브랜치에다가 전부 파니까 버전 카탈로그 공부한것도 올라가버리네요... 이건 제가 어떻게든 수정하겠습니다
일단은 버전카탈로그 코드 삭제하고 올립니다.

@hsgo2430
기존 PR을 머지하고, 다음 스터디를 진행해주셔도 무방합니다! 원래 저번 1주차에서 스터디 진행하고 머지해야했는데, 못한채로 테스트 코드 COMMIT 이 들어가서 혼동이 생겼나 보군요.. (괜찮습니다)

Copy link
Contributor

@Jokwanhee Jokwanhee left a comment

Choose a reason for hiding this comment

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

고생하셨습니다. 👍

전체적으로 JUnit 사용법과 테스트 코드를 작성하는 감각을 키우기 위한 것이 이번 스터디의 목적입니다. 저도 테스트 코드에 대해서는 잘 몰라서..

하지만 조금 고려해야할 부분은 너무 String 비교가 많습니다. 논리적으로 온도가 있으면, 입력되는 섭씨의 값이 올바른지, 화씨에서 켈빈으로 변환했을 때 올바른 값이 유도되는 지를 테스트 코드로 작성했으면 어땠을까 합니다.

class NotificationTest {
@Test
fun num50_Notification_print50Notification() {
val notificationSummary = NotificationSummary()
Copy link
Contributor

Choose a reason for hiding this comment

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

동일한 객체를 사용하기 위해서 JUnit 에서는 @before를 사용해서 변수를 정의할 수 있습니다!

private lateinit var notificationSummary: NotificationSummary

@Before
fun setUp(){
  notificationSummary = NotificatioinSummary()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

중복으로 사용할 변수를 @before 어노테이션을 이용해서 작성한다면 제 코드에서 필요한 코드만 작성할 수 있겠네요!
감사합니다!

val numOfNotification = 200

val outputStream = ByteArrayOutputStream()
System.setOut(PrintStream(outputStream))
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.

print를 통해서 결과를 출력하게 되는데 이때 출력되는 문자열을 가져오기 위해서 사용하였습니다!

val initialMeasurement = 10.0
val initialUnit = "Fahrenheit"
val finalUnit = "Kelvin"
val conversionFormula = { fahrenheit: Double -> (fahrenheit - 32) * 5/9 + 273.15}
Copy link
Contributor

Choose a reason for hiding this comment

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

5/9 -> Int / Int 이기 때문에 적합하지 않습니다! 5.0/9 와 같이 소수점 타입인 double 또는 float으로 하나 지정해주어야 원하는 연산식을 유도할 수 있을 것 같네요.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

C였으면 오류가 나왔을 코드네요... 이건 제 실수가 맞는거같아요..
정수형과 실수형 항상 구분해서 사용하도록 기억하겠습니다!

@hsgo2430
Copy link
Contributor Author

hsgo2430 commented Jun 8, 2024

고생하셨습니다. 👍

전체적으로 JUnit 사용법과 테스트 코드를 작성하는 감각을 키우기 위한 것이 이번 스터디의 목적입니다. 저도 테스트 코드에 대해서는 잘 몰라서..

하지만 조금 고려해야할 부분은 너무 String 비교가 많습니다. 논리적으로 온도가 있으면, 입력되는 섭씨의 값이 올바른지, 화씨에서 켈빈으로 변환했을 때 올바른 값이 유도되는 지를 테스트 코드로 작성했으면 어땠을까 합니다.

이부분은 제가 이해를 잘못해서 생긴 문제인거같아요!

저는 과제를 코드랩에 있는 아래의 사진이 맞는지 아닌지 테스트 하는 코드를 작성하는 줄 알고 문자열로 진행 했어요
image

확실히 관희형이 말씀하신 게 더 옳은거 같아서 assertEquals의 다양한 형태로 테스트를 해보는 연습을 해볼게요!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍏 안드로이드 Android Skill 🔥 PR PR 올립니다~ 😶‍🌫️ 미흡 숨어야지..
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[JUnit] 단위 테스트
2 participants