Loading...
Spring Framework Reference Documentation 7.0.2의 Spring JUnit 4 Testing Annotations의 한국어 번역본입니다.
아래의 경우에 피드백에서 신고해주신다면 반영하겠습니다.
감사합니다 :)
JUnit 4 support is deprecated since Spring Framework 7.0 in favor of the
SpringExtensionand JUnit Jupiter.
다음 어노테이션들은 SpringRunner, Spring’s JUnit 4 rules, 또는 Spring’s JUnit 4 support classes와 함께 사용할 때에만 지원됩니다:
@IfProfileValue@IfProfileValue는 어노테이션이 적용된 테스트 클래스 또는 테스트 메서드가 특정 테스트 환경에 대해 활성화되어 있음을 나타냅니다. 설정된 ProfileValueSource가 제공된 name에 대해 일치하는 value를 반환하면 테스트는 활성화됩니다. 그렇지 않으면 테스트는 비활성화되고, 사실상 무시됩니다.
@IfProfileValue는 클래스 레벨, 메서드 레벨 또는 둘 다에 적용할 수 있습니다.
어떤 클래스 및 그 서브클래스 내의 메서드에 대해서든, 클래스 레벨에서의 @IfProfileValue 사용이 메서드 레벨에서의 사용보다 우선합니다. 구체적으로, 테스트는 클래스 레벨과 메서드 레벨 모두에서 활성화되어 있을 때 활성화됩니다. @IfProfileValue가 없다는 것은 테스트가 암묵적으로 활성화되어 있음을 의미합니다. 이는 JUnit 4의 @Ignore 어노테이션의 의미와 유사하지만, @Ignore가 존재하면 항상 테스트가 비활성화된다는 점이 다릅니다.
다음 예제는 @IfProfileValue 어노테이션이 있는 테스트를 보여줍니다:
1@IfProfileValue(name="java.vendor", value="Oracle Corporation") // (1) 2@Test 3public void testProcessWhichRunsOnlyOnOracleJvm() { 4 // some logic that should run only on Java VMs from Oracle Corporation 5}
| 1 | Java vendor가 "Oracle Corporation"일 때만 이 테스트를 실행합니다. |
1@IfProfileValue(name="java.vendor", value="Oracle Corporation") // (1) 2@Test 3fun testProcessWhichRunsOnlyOnOracleJvm() { 4 // some logic that should run only on Java VMs from Oracle Corporation 5}
| 1 | Java vendor가 "Oracle Corporation"일 때만 이 테스트를 실행합니다. |
또는, @IfProfileValue를 values 목록( OR 의미론과 함께)으로 설정하여 JUnit 4 환경에서 TestNG와 유사한 테스트 그룹 지원을 구현할 수 있습니다.
다음 예제를 보십시오:
1@IfProfileValue(name="test-groups", values={"unit-tests", "integration-tests"}) // (1) 2@Test 3public void testProcessWhichRunsForUnitOrIntegrationTestGroups() { 4 // some logic that should run only for unit and integration test groups 5}
| 1 | 단위 테스트와 통합 테스트에 대해 이 테스트를 실행합니다. |
1@IfProfileValue(name="test-groups", values=["unit-tests", "integration-tests"]) // (1) 2@Test 3fun testProcessWhichRunsForUnitOrIntegrationTestGroups() { 4 // some logic that should run only for unit and integration test groups 5}
| 1 | 단위 테스트와 통합 테스트에 대해 이 테스트를 실행합니다. |
@ProfileValueSourceConfiguration@ProfileValueSourceConfiguration은 테스트 클래스에 적용되어 @IfProfileValue 어노테이션을 통해 설정된 프로필 값을 조회할 때 사용할 ProfileValueSource의 타입을 지정하는 어노테이션입니다. 테스트에 대해 @ProfileValueSourceConfiguration이 선언되지 않은 경우, 기본적으로 SystemProfileValueSource가 사용됩니다. 다음 예제는
@ProfileValueSourceConfiguration 사용 방법을 보여줍니다:
1@ProfileValueSourceConfiguration(CustomProfileValueSource.class) // (1) 2public class CustomProfileValueSourceTests { 3 // class body... 4}
| 1 | 커스텀 프로필 값 소스를 사용합니다. |
1@ProfileValueSourceConfiguration(CustomProfileValueSource::class) // (1) 2class CustomProfileValueSourceTests { 3 // class body... 4}
| 1 | 커스텀 프로필 값 소스를 사용합니다. |
@Timed@Timed는 어노테이션이 적용된 테스트 메서드가 지정된 시간(밀리초 단위) 안에 실행을 끝내야 함을 나타냅니다. 테스트 실행 시간이 지정된 시간 범위를 초과하면 테스트는 실패합니다.
시간 범위에는 테스트 메서드 자체의 실행, 테스트의 반복 실행(@Repeat 참조)뿐만 아니라 테스트 픽스처의 설정 또는 해제도 포함됩니다. 다음 예제는 사용 방법을 보여줍니다:
1@Timed(millis = 1000) // (1) 2public void testProcessWithOneSecondTimeout() { 3 // some logic that should not take longer than 1 second to run 4}
| 1 | 테스트의 시간 범위를 1초로 설정합니다. |
1@Timed(millis = 1000) // (1) 2fun testProcessWithOneSecondTimeout() { 3 // some logic that should not take longer than 1 second to run 4}
| 1 | 테스트의 시간 범위를 1초로 설정합니다. |
Spring의 @Timed 어노테이션은 JUnit 4의 @Test(timeout=…) 지원과는 다른 의미론을 가집니다. 구체적으로, JUnit 4가 테스트 실행 타임아웃을 처리하는 방식(즉, 테스트 메서드를 별도의 Thread에서 실행하는 방식) 때문에, @Test(timeout=…)은 테스트가 너무 오래 걸리면 미리 테스트를 실패시킵니다. 반면 Spring의 @Timed는 테스트를 미리 실패시키지 않고 테스트가 완료될 때까지 기다린 후 실패시킵니다.
@Repeat@Repeat는 어노테이션이 적용된 테스트 메서드가 반복해서 실행되어야 함을 나타냅니다. 테스트 메서드가 실행될 횟수는 어노테이션에서 지정합니다.
반복 실행의 범위에는 테스트 메서드 자체의 실행뿐만 아니라 테스트 픽스처의 설정 또는 해제도 포함됩니다.
SpringMethodRule과 함께 사용할 때는, 범위에 TestExecutionListener 구현에 의한 테스트 인스턴스 준비도 추가로 포함됩니다. 다음 예제는 @Repeat 어노테이션 사용 방법을 보여줍니다:
1@Repeat(10) // (1) 2@Test 3public void testProcessRepeatedly() { 4 // ... 5}
| 1 | 이 테스트를 10번 반복합니다. |
1@Repeat(10) // (1) 2@Test 3fun testProcessRepeatedly() { 4 // ... 5}
| 1 | 이 테스트를 10번 반복합니다. |
@DisabledInAotMode
Spring JUnit Jupiter Testing Annotations