문서의 선택한 두 판 사이의 차이를 보여줍니다.
다음 판 | 이전 판 마지막 판 양쪽 다음 판 | ||
java:junit:5 [2017/07/04 08:44] kwon37xi 만듦 |
java:junit:5 [2022/08/23 13:08] kwon37xi [IntelliJ IDEA JUnit 5 migration] |
||
---|---|---|---|
줄 1: | 줄 1: | ||
====== JUnit 5 ====== | ====== JUnit 5 ====== | ||
+ | * https:// | ||
+ | * [[java: | ||
+ | * [[java: | ||
+ | * [[https:// | ||
+ | |||
+ | ===== API 개념 ===== | ||
+ | * **테스트 코드 작성을 위한 API**와, 그렇게 작성한 **테스트를 수행하는 Engine**을 분리하였다. | ||
+ | |||
+ | |||
+ | ==== JUnit 4로 작성한 코드 ==== | ||
+ | * JUnit 4 API로 작성한 코드도 JUnit 5에서 실행가능하다. | ||
+ | * 이 경우 [[https:// | ||
+ | |||
+ | ==== JUnit 5로 작성한 코드 ==== | ||
+ | * JUnit 5는 [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | |||
+ | ===== Gradle ===== | ||
+ | * [[https:// | ||
+ | * [[: | ||
+ | * [[: | ||
+ | test { | ||
+ | useJUnitPlatform() | ||
+ | } | ||
+ | |||
+ | // spring-boot-starter-test 로 의존성 지정시 | ||
+ | testImplementation(' | ||
+ | exclude group: ' | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== 주유 Annotations ===== | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | ===== Assumptions ===== | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | ===== IntelliJ IDEA JUnit 5 migration ===== | ||
+ | * **Refactor -> Migrate Packages and Classes -> JUnit (4.x -> 5.0)** 을 실행하여 리팩토링을 바로 실행할 수 있다. | ||
+ | * 그 이후 '' | ||
+ | * **Structural Replace**를 사용하면 쉽게 된다. | ||
+ | * 변경된 파일들을 모두 선택하고 **Organize Imports(Ctrl+Alt+o)**를 해주는게 좋다. | ||
+ | * 기존 [[java: | ||
+ | * '' | ||
+ | * **Structural Search**를 사용한다. | ||
+ | * Live Templates 에서 다음과 같이 만든다. | ||
+ | * Applicable : '' | ||
+ | * Abbreviation : '' | ||
+ | * Description : '' | ||
+ | * Reformat according to style : check | ||
+ | * Use static import if possible : check | ||
+ | * Shorten FQ names : check | ||
+ | * Edit Variables -> '' | ||
+ | * Expression : '' | ||
+ | < | ||
+ | org.junit.jupiter.api.Assertions.assertThrows($EXCEPTION$.class, | ||
+ | $SELECTION$ | ||
+ | }); | ||
+ | </ | ||
+ | * 테스트 대상 예외 클래스의 이름을 복사('' | ||
+ | * '' | ||
+ | * 특히, '' | ||
+ | * 테스트 클래스 중에 '' | ||
+ | * package private 으로 전환하면 불필요하게 테스트 클래스가 자동완성으로 나오는 일 등이 줄어든다. | ||
+ | ==== Inspection 으로 하나씩 변경하기 ==== | ||
+ | |||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[: | ||
+ | * **Settings -> Editor -> Inspections** : **JVM languages -> JUnit 4 test can be JUnit 5** 항목이 켜져 있어야 한다. | ||
+ | * JUnit 4 테스트 클래스에서 '' | ||
+ | * '' | ||
+ | |||
+ | ===== 참조 ===== | ||
* [[https:// | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||