728x90
https://junit.org/junit5/docs/current/user-guide/#writing-tests
JUnit 5 User Guide
Although the JUnit Jupiter programming model and extension model do not support JUnit 4 features such as Rules and Runners natively, it is not expected that source code maintainers will need to update all of their existing tests, test extensions, and custo
junit.org
잘못된 해석이 있다면 알려주세요 ⌚️
Annotations
주석설명
JUnit Jupiter supports the following annotations for configuring tests and extending the framework.
Unless otherwise stated, all core annotations are located in the org.junit.jupiter.api package in the junit-jupiter-api module.
AnnotationDescription
@Test | Denotes that a method is a test method. Unlike JUnit 4’s @Test annotation, this annotation does not declare any attributes, since test extensions in JUnit Jupiter operate based on their own dedicated annotations. Such methods are inherited unless they are overridden. 메서드가 테스트 메서드임을 나타낸다. JUnit 4의 @Test 주석과 달리, 이 주석은 전용 주석을 기반으로 JUnit Jupiter의 테스트 확장이 작동하기 때문에 어떤 속성도 선언하지 않는다. 이러한 메서드는 재정의되지 않는 한 상속된다. |
@ParameterizedTest | Denotes that a method is a parameterized test. Such methods are inherited unless they are overridden. 메서드가 매개 변수화된 테스트임을 나타낸다. 이러한 메서드는 재정의되지 않는 한 상속된다. |
@RepeatedTest | Denotes that a method is a test template for a repeated test. Such methods are inherited unless they are overridden. 메서드가 반복 테스트를위한 테스트 템플릿임을 나타낸다. 이러한 메서드는 재정의되지 않는 한 상속된다. |
@TestFactory | Denotes that a method is a test factory for dynamic tests. Such methods are inherited unless they are overridden. 메서드가 동적 테스트를 위한 테스트 팩토리임을 나타낸다. 이러한 메서드는 재정의되지 않는 한 상속된다. |
@TestTemplate | Denotes that a method is a template for test cases designed to be invoked multiple times depending on the number of invocation contexts returned by the registered providers. Such methods are inherited unless they are overridden. 메서드가 등록 된 공급자가 반환하는 호출 컨텍스트 수에 따라 여러 번 호출되도록 설계된 테스트 케이스의 템플릿임을 나타낸다. 이러한 메서드는 재정의되지 않는 한 상속된다. |
@TestClassOrder | Used to configure the test class execution order for @Nested test classes in the annotated test class. Such annotations are inherited. 주석이 달린 테스트 클래스에서 @Nested 테스트 클래스에 대한 테스트 클래스 실행 순서를 구성하는 데 사용된다. 이러한 주석은 상속된다. |
@TestMethodOrder | Used to configure the test method execution order for the annotated test class; similar to JUnit 4’s @FixMethodOrder. Such annotations are inherited. 주석이 달린 테스트 클래스에 대한 테스트 메서드 실행 순서를 구성하는 데 사용된다. JUnit 4의 @FixMethodOrder와 유사하다. 이러한 주석은 상속된다. |
@TestInstance | Used to configure the test instance lifecycle for the annotated test class. Such annotations are inherited. 주석이 달린 테스트 클래스의 테스트 인스턴스 라이프 사이클을 구성하는 데 사용된다. 이러한 주석은 상속된다. |
@DisplayName | Declares a custom display name for the test class or test method. Such annotations are not inherited. 테스트 클래스 또는 테스트 메서드에 대한 사용자 정의 표시 이름을 선언한다. 이러한 주석은 상속되지 않는다. |
@DisplayNameGeneration | Declares a custom display name generator for the test class. Such annotations are inherited. 테스트 클래스에 대한 사용자 정의 표시 이름 생성기를 선언한다. 이러한 주석은 상속된다. |
@BeforeEach | Denotes that the annotated method should be executed before each @Test, @RepeatedTest, @ParameterizedTest, or @TestFactory method in the current class; analogous to JUnit 4’s @Before. Such methods are inherited – unless they are overridden or superseded (i.e., replaced based on signature only, irrespective of Java’s visibility rules). @BeforeEach 어노테이션은 현재 클래스의 @Test, @RepeatedTest, @ParameterizedTest, @TestFactory 메소드가 실행되기 전에 실행되어야 하는 메소드를 지정한다. JUnit 4의 @Before와 유사하다. 이 메소드들은 오버라이딩되지 않는 한 상속된다. 다만 시그니처만으로 대체되는 경우(Java의 가시성 규칙과 무관하게)에는 오버라이딩 대상에서 제외된다. |
@AfterEach | Denotes that the annotated method should be executed after each @Test, @RepeatedTest, @ParameterizedTest, or @TestFactory method in the current class; analogous to JUnit 4’s @After. Such methods are inherited – unless they are overridden or superseded (i.e., replaced based on signature only, irrespective of Java’s visibility rules). 해당 어노테이션은 현재 클래스 내의 각 @Test, @RepeatedTest, @ParameterizedTest, @TestFactory 메서드가 실행된 후에 실행되는 메서드를 지정한다. 이는 JUnit 4의 @After와 유사하다. 이러한 메서드는 재정의되지 않는 한 상속된다. |
@BeforeAll | Denotes that the annotated method should be executed before all @Test, @RepeatedTest, @ParameterizedTest, and @TestFactory methods in the current class; analogous to JUnit 4’s @BeforeClass. Such methods are inherited – unless they are hidden, overridden, or superseded, (i.e., replaced based on signature only, irrespective of Java’s visibility rules) – and must be static unless the "per-class" test instance lifecycle is used. 현재 클래스의 모든 @Test, @RepeatedTest, @ParameterizedTest 및 @TestFactory 메서드 이전에 실행해야 함을 나타낸다. JUnit 4의 @BeforeClass와 유사하다. 이러한 메서드는 상속된다. (서명만으로 교체되며 Java의 가시성 규칙과 관계없이 숨겨지거나 대체될 수 있음) 이때 "per-class" 테스트 인스턴스 라이프 사이클을 사용하지 않는 한 정적(static)이어야한다. |
@AfterAll | Denotes that the annotated method should be executed after all @Test, @RepeatedTest, @ParameterizedTest, and @TestFactory methods in the current class; analogous to JUnit 4’s @AfterClass. Such methods are inherited – unless they are hidden, overridden, or superseded, (i.e., replaced based on signature only, irrespective of Java’s visibility rules) – and must be static unless the "per-class" test instance lifecycle is used. 현재 클래스의 모든 @Test, @RepeatedTest, @ParameterizedTest 및 @TestFactory 메서드 이후에 실행해야 함을 나타낸다. JUnit 4의 @AfterClass와 유사하다. 이러한 메서드는 상속된다. (서명만으로 교체되며 Java의 가시성 규칙과 관계없이 숨겨지거나 대체될 수 있음) 이때 "per-class" 테스트 인스턴스 라이프 사이클을 사용하지 않는 한 정적(static)이어야한다. |
@Nested | Denotes that the annotated class is a non-static nested test class. On Java 8 through Java 15, @BeforeAll and @AfterAll methods cannot be used directly in a @Nested test class unless the "per-class" test instance lifecycle is used. Beginning with Java 16, @BeforeAll and @AfterAll methods can be declared as static in a @Nested test class with either test instance lifecycle mode. Such annotations are not inherited. 주석이 지정된 클래스가 정적이 아닌 중첩 테스트 클래스임을 나타낸다. Java 8부터 Java 15까지는 "per-class" 테스트 인스턴스 라이프 사이클을 사용하지 않는 한 @BeforeAll 및 @AfterAll 메서드를 직접 @Nested 테스트 클래스에서 사용할 수 없다. Java 16부터는 @BeforeAll 및 @AfterAll 메서드를 @Nested 테스트 클래스에서 정적(static)으로 선언하면 테스트 인스턴스 라이프 사이클 모드를 사용하여 선언할 수 있다. 이러한 주석은 상속되지 않는다. |
@Tag | Used to declare tags for filtering tests, either at the class or method level; analogous to test groups in TestNG or Categories in JUnit 4. Such annotations are inherited at the class level but not at the method level. 테스트를 필터링하기 위해 클래스 또는 메서드 수준에서 태그를 선언하는 데 사용된다. TestNG의 test 그룹이나 JUnit 4의 Categories와 유사하다. 이러한 주석은 클래스 수준에서 상속된다. 하지만 메서드 수준에서는 상속되지 않는다. |
@Disabled | Used to disable a test class or test method; analogous to JUnit 4’s @Ignore. Such annotations are not inherited. 테스트 클래스 또는 테스트 메서드를 비활성화하기 위해 사용된다. JUnit 4의 @Ignore와 유사하다. 이러한 주석은 상속되지 않는다. |
@Timeout | Used to fail a test, test factory, test template, or lifecycle method if its execution exceeds a given duration. Such annotations are inherited. 실행 시간이 지정된 지속 시간을 초과하면 테스트, 테스트 팩토리, 테스트 템플릿 또는 라이프 사이클 메서드를 실패시키는 데 사용한다. 이러한 주석은 상속된다. |
@ExtendWith | Used to register extensions declaratively. Such annotations are inherited. 해당 어노테이션은 테스트 확장을 선언적으로 등록하는 데 사용된다. 이러한 어노테이션은 상속된다. |
@RegisterExtension | Used to register extensions programmatically via fields. Such fields are inherited unless they are shadowed. 해당 어노테이션은 필드를 통해 프로그래밍 방식으로 확장을 등록하는 데 사용된다. 이러한 필드는 가려지지 않는 한 상속된다. |
@TempDir | Used to supply a temporary directory via field injection or parameter injection in a lifecycle method or test method; located in the org.junit.jupiter.api.io package. 해당 어노테이션은 라이프사이클 메서드 또는 테스트 메서드에서 필드 주입 또는 매개변수 주입을 통해 임시 디렉터리를 제공하는 데 사용된다. 이 어노테이션은 org.junit.jupiter.api.io 패키지에 있다. |
728x90
'Web > spring' 카테고리의 다른 글
[Spring Junit Test] 2.11. Test Instance Lifecycle (0) | 2023.03.21 |
---|---|
[Spring Junit Test] 2.5. Assertions (0) | 2023.03.20 |
[Spring Batch] Configuring and Running a Job - (6) Advanced Metadata Usage (0) | 2023.03.19 |
[Spring Batch] Configuring and Running a Job - (5) Running a Job (0) | 2023.03.19 |
[Spring Batch] Configuring and Running a Job - (4) Configuring a JobLauncher (0) | 2023.03.17 |