-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
학습 테스트 실습 리뷰 부탁드립니다 #1843
학습 테스트 실습 리뷰 부탁드립니다 #1843
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package study; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
@DisplayName("Set Collection에 대한 학습 테스트") | ||
public class SetTest { | ||
private Set<Integer> numbers; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
numbers = new HashSet<>(); | ||
numbers.add(1); | ||
numbers.add(1); | ||
numbers.add(2); | ||
numbers.add(3); | ||
} | ||
|
||
@Test | ||
@DisplayName("Set size 확인") | ||
public void setTest01() throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 물론 DisplayName으로 어떤 테스트인지 파악할 수 있지만 함수명도 어떤 의미의 테스트인지 담을 수록 좋습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 함수명... 변수명... |
||
assertThat(numbers.size()).isEqualTo(3); | ||
} | ||
|
||
|
||
@ParameterizedTest | ||
@ValueSource(ints = {1, 2, 3}) | ||
@DisplayName("Set 값 존재여부 확인") | ||
public void setTest02(int inputNumber) throws Exception { | ||
assertThat(numbers.contains(inputNumber)).isTrue(); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource(value = {"0:false","1:true","2:true","3:true","4:false"}, delimiter = ':') | ||
@DisplayName("Set 값 존재 확인") | ||
public void setTest03(int inputNumber, boolean isFree) throws Exception { | ||
assertThat(numbers.contains(inputNumber)).isEqualTo(isFree); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 커밋 로그를 의미있는 단위로 나눠주시면 좋습니다. feat (feature) 아래 링크 참고하셔서 미션 수행시 기능 단위로 Commit Log 남길때 참고해보시면 좋을거 같아요 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 커밋 컨벤션 처음 알았네요! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package study; | ||
|
||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
// String 클래스에 대한 학습 테스트 | ||
@DisplayName("String 클래스에 대한 학습 테스트") | ||
public class StringTest { | ||
|
||
@Test | ||
@DisplayName("문자열 1,2 나누기") | ||
public void stringTest01() throws Exception { | ||
String[] result = "1,2".split(","); | ||
// assertThat(result).contains("1", "2"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 의미없는 주석은 삭제하겠습니다 |
||
assertThat(result).containsExactly("1", "2"); | ||
} | ||
|
||
@Test | ||
@DisplayName("문자열 1, 나누기") | ||
public void stringTest02() throws Exception { | ||
String[] result = "1,".split(","); | ||
assertThat(result).containsExactly("1"); | ||
} | ||
|
||
@Test | ||
@DisplayName("문자열 (1,2) substring 으로 ()제거하기") | ||
public void stringTest03() throws Exception { | ||
String data = "(1,2)"; | ||
String result = data.substring(1, data.length()-1); | ||
assertThat(result).isEqualTo("1,2"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 잘 작성하셨네요 💯 추가로 아래처럼 given, when, then 순으로 작성하시면
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. given, when, then 템플릿으로 진행하겠습니다 |
||
} | ||
|
||
@Test | ||
@DisplayName("문자열 abc 뽑아내기") | ||
public void stringTest04() throws Exception { | ||
String data = "abc"; | ||
|
||
assertEquals(data.charAt(0), 'a'); | ||
assertEquals(data.charAt(1), 'b'); | ||
assertEquals(data.charAt(2), 'c'); | ||
|
||
assertThatThrownBy(() -> { | ||
data.charAt(3); | ||
}).isInstanceOf(IndexOutOfBoundsException.class) | ||
.hasMessageContaining("String index out of range: 3"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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.
@DisplayName 으로 어떠한 테스트 인지 파악할 수 있어 좋네요 💯
메소드 이름이나 @DisplayName이 어느 정도까지 구체적이어야 하는지에 대해서 정답은 없다고 생각합니다.
다만, 이름만으로도 언제 이 메서드를 호출해야 하는지 또 어떤 테스트를 하는 것인지 의미를 파악할 수 있도록 작성하시면 다른 사람이 볼때도 쉽게 의도를 파악할 수 있을거 같네요. 아래 자료도 참고해 보시면 좋을거 같아요. 👍
https://woowacourse.github.io/javable/2020-04-26/Method-Naming
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.
해당 링크 404 뜨고 있습니다... ㅜㅜㅜㅜㅜ
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.
찾았습니다.
https://woowacourse.github.io/javable/post/2020-04-26-Method-Naming/