-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: main
Are you sure you want to change the base?
[#20] 단위테스트 #22
Conversation
@hsgo2430 |
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.
고생하셨습니다. 👍
전체적으로 JUnit 사용법과 테스트 코드를 작성하는 감각을 키우기 위한 것이 이번 스터디의 목적입니다. 저도 테스트 코드에 대해서는 잘 몰라서..
하지만 조금 고려해야할 부분은 너무 String 비교가 많습니다. 논리적으로 온도가 있으면, 입력되는 섭씨의 값이 올바른지, 화씨에서 켈빈으로 변환했을 때 올바른 값이 유도되는 지를 테스트 코드로 작성했으면 어땠을까 합니다.
class NotificationTest { | ||
@Test | ||
fun num50_Notification_print50Notification() { | ||
val notificationSummary = NotificationSummary() |
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.
동일한 객체를 사용하기 위해서 JUnit 에서는 @before를 사용해서 변수를 정의할 수 있습니다!
private lateinit var notificationSummary: NotificationSummary
@Before
fun setUp(){
notificationSummary = NotificatioinSummary()
}
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.
중복으로 사용할 변수를 @before 어노테이션을 이용해서 작성한다면 제 코드에서 필요한 코드만 작성할 수 있겠네요!
감사합니다!
val numOfNotification = 200 | ||
|
||
val outputStream = ByteArrayOutputStream() | ||
System.setOut(PrintStream(outputStream)) |
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.
print를 통해서 결과를 출력하게 되는데 이때 출력되는 문자열을 가져오기 위해서 사용하였습니다!
val initialMeasurement = 10.0 | ||
val initialUnit = "Fahrenheit" | ||
val finalUnit = "Kelvin" | ||
val conversionFormula = { fahrenheit: Double -> (fahrenheit - 32) * 5/9 + 273.15} |
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.
5/9 -> Int / Int 이기 때문에 적합하지 않습니다! 5.0/9 와 같이 소수점 타입인 double 또는 float으로 하나 지정해주어야 원하는 연산식을 유도할 수 있을 것 같네요.
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.
C였으면 오류가 나왔을 코드네요... 이건 제 실수가 맞는거같아요..
정수형과 실수형 항상 구분해서 사용하도록 기억하겠습니다!
👻 이슈
✍️ 공부 내용 적어주세요.
🦖 이슈가 있었다면 적어주세요.
👀 참조 레퍼런스