사용자 도구

사이트 도구


java:junit:5

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
다음 판 양쪽 다음 판
java:junit:5 [2020/05/24 20:18]
kwon37xi
java:junit:5 [2020/07/08 13:25]
kwon37xi
줄 1: 줄 1:
 ====== JUnit 5 ====== ====== JUnit 5 ======
 +  * https://mvnrepository.com/artifact/org.junit
 +  * [[java:assertj|AssertJ]]
 +
 +===== API 개념 =====
 +  * **테스트 코드 작성을 위한 API**와, 그렇게 작성한 **테스트를 수행하는 Engine**을 분리하였다.
 +==== JUnit 4로 작성한 코드 ====
 +  * JUnit 4 API로 작성한 코드도 JUnit 5에서 실행가능하다.
 +  * 이 경우 [[https://mvnrepository.com/artifact/org.junit.vintage/junit-vintage-engine|junit-vintage-engine]] 으로 해당 코드를 수행한다.
 +
 +==== JUnit 5로 작성한 코드 ====
 +  * JUnit 5는 [[https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api|junit-jupiter-api]]로 테스트 코드를 작성하고
 +  * [[https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine|junit-jupiter-engine]]으로 테스트 코드를 수행한다.
 +
  
 ===== Gradle ===== ===== Gradle =====
줄 5: 줄 18:
 test { test {
     useJUnitPlatform()     useJUnitPlatform()
 +}
 +
 +// spring-boot-starter-test 로 의존성 지정시
 +testImplementation('org.springframework.boot:spring-boot-starter-test') {
 +    exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' // junit4 지원 제외
 } }
 </code> </code>
 +
 +===== 주유 Annotations =====
 +  * ''@DisplayName("설명")'' : 테스트 설명을 일반 텍스트로 지정 가능. 가독성이 높아짐.
 +  * ''@Disabled("설명")'' : 테스트 안하게 함. 설명도 지정.
 +  * ''@BeforeAll'' : 테스트 클래스 초기화시 한 번 실행
 +  * ''@BeforeEach'' : 모든 테스트 메소드 실행 직전 실행
 +  * ''@Test'' : 테스트
 +  * ''@AfterEach'' : 모든 테스트 메소드 실행 직후 실행
 +  * ''@AfterAll'' : 테스트 클래스가 종료될 때 실행
 +  * ''@Nested'' : 중첩 클래스에 지정. 중첩 테스트가 만들기.
 +  * ''@Tag'' : 클래스나 메서드에 붙인다. 테스트 실행시 특정 태그가 붙은 것만 실행/제외 할 수 있다.
 +
 +===== Assumptions =====
 +  * ''assumTrue'' : boolean 인자가 true 일 때만 테스트 실행
 +  * ''assumFalse'' : boolean 인자가 false 일 때만 테스트 실행
 +  * ''assumeThat(boolean/BooleanSupplier, Executable)'' : boolean 이 true이면 executable lambda 실행
  
 ===== 참조 ===== ===== 참조 =====
줄 41: 줄 75:
   * [[https://www.javaworld.com/article/3537563/junit-5-tutorial-part-1-unit-testing-with-junit-5-mockito-and-hamcrest.html|JUnit 5 tutorial, part 1: Unit testing with JUnit 5, Mockito, and Hamcrest | JavaWorld]]   * [[https://www.javaworld.com/article/3537563/junit-5-tutorial-part-1-unit-testing-with-junit-5-mockito-and-hamcrest.html|JUnit 5 tutorial, part 1: Unit testing with JUnit 5, Mockito, and Hamcrest | JavaWorld]]
   * [[https://www.javaworld.com/article/3543268/junit-5-tutorial-part-2-unit-testing-spring-mvc-with-junit-5.html|JUnit 5 tutorial, part 2: Unit testing Spring MVC with JUnit 5 | JavaWorld]]   * [[https://www.javaworld.com/article/3543268/junit-5-tutorial-part-2-unit-testing-spring-mvc-with-junit-5.html|JUnit 5 tutorial, part 2: Unit testing Spring MVC with JUnit 5 | JavaWorld]]
 +  * [[https://blogs.oracle.com/javamagazine/junit-5-6-makes-testing-easy-with-new-features|JUnit 5.6 Makes Testing Easy with New Features]]
java/junit/5.txt · 마지막으로 수정됨: 2022/08/31 10:25 저자 kwon37xi