application test : junit5 - 조건에 따라 테스트 실행하기

This commit is contained in:
haerong22
2021-02-24 17:14:47 +09:00
parent 181cef092f
commit ea6c1e3ae1
2 changed files with 150 additions and 67 deletions

View File

@@ -1,6 +1,7 @@
package com.example.apptest; package com.example.apptest;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
import org.junit.jupiter.api.condition.*;
import java.time.Duration; import java.time.Duration;
@@ -10,79 +11,161 @@ import static org.junit.jupiter.api.Assertions.*;
class StudyTest { class StudyTest {
@Test @Test
@DisplayName("assertTimeout test") @DisplayName("DisabledIfEnvironmentVariable test")
void test_4() { @DisabledIfEnvironmentVariable(named = "TEST_ENV", matches = "KIM")
assertTimeoutPreemptively(Duration.ofMillis(100), () -> { void test_12() {
Thread.sleep(300); System.out.println("테스트");
new Study(10);
});
// assertTimeout( 시간, 실행구문 )
// 실행 구문이 끝날 때 까지 기다렸다가 결과를 출력한다.
assertTimeout(Duration.ofMillis(100), () -> {
Thread.sleep(300);
new Study(10);
});
}
@Test
@DisplayName("assertThrows test")
void test_3() {
// 리턴 값은 해당 예외 타입이다.
IllegalArgumentException exception =
assertThrows(IllegalArgumentException.class, () -> new Study(-10));
// 에러 메시지 확인도 가능하다
assertEquals("limit은 0보다 커야 한다.", exception.getMessage());
}
@Test
@DisplayName("assertAll test")
void test_2() {
Study study = new Study(-10);
assertAll(
() -> assertTrue(study.getLimit() > 0, "스터디 최대 참석 가능 인원은 0보다 커야 한다."),
() -> assertEquals(StudyStatus.DRAFT, study.getStatus(), "스터디를 처음 만들면 status가 DRAFT 이어야 한다.")
);
}
@Test
@DisplayName("assertTrue test")
void test_1() {
Study study = new Study(10); Study study = new Study(10);
// assertTrue( 조건, 실패시 출력 메시지 ) assertTrue(study.getLimit() > 0, () -> "limit 는 0보다 커야한다.");
assertTrue(study.getLimit() > 0, "스터디 최대 참석 가능 인원은 0보다 커야 한다.");
} }
@Test @Test
@DisplayName("assertEquals test") @DisplayName("EnabledIfEnvironmentVariable test")
void test() { @EnabledIfEnvironmentVariable(named = "TEST_ENV", matches = "KIM")
Study study = new Study(); void test_11() {
// assertEquals( 기대값, 실제값, 실패시 메시지 ) System.out.println("테스트");
Study study = new Study(10);
assertEquals(StudyStatus.DRAFT, study.getStatus(), "스터디를 처음 만들면 status가 DRAFT 이어야 한다."); assertTrue(study.getLimit() > 0, () -> "limit 는 0보다 커야한다.");
} }
@Test // @Test
void create_new_study() { // @DisplayName("EnabledOnJre test")
Study study = new Study(); // @EnabledOnJre({JRE.JAVA_8, JRE.JAVA_11})
assertNotNull(study); // void test_10() {
System.out.println("create 테스트"); // System.out.println("테스트");
} // Study study = new Study(10);
// assertTrue(study.getLimit() > 0, () -> "limit 는 0보다 커야한다.");
// }
//
// @Test
// @DisplayName("DisabledOnJre test")
// @DisabledOnJre(JRE.JAVA_11)
// void test_9() {
// System.out.println("테스트");
// Study study = new Study(10);
// assertTrue(study.getLimit() > 0, () -> "limit 는 0보다 커야한다.");
// }
//
// @Test
// @DisplayName("EnabledOnOs test")
// @EnabledOnOs({OS.WINDOWS, OS.MAC})
// void test_8() {
// System.out.println("테스트");
// Study study = new Study(10);
// assertTrue(study.getLimit() > 0, () -> "limit 는 0보다 커야한다.");
// }
//
// @Test
// @DisplayName("DisabledOnOs test")
// @DisabledOnOs(OS.WINDOWS)
// void test_7() {
// System.out.println("테스트");
// Study study = new Study(10);
// assertTrue(study.getLimit() > 0, () -> "limit 는 0보다 커야한다.");
// }
@Test // @Test
@DisplayName("스터디 생성하기!! 💖") // @DisplayName("assumingThat test")
void create_new_study_2() { // void test_6() {
System.out.println("create1 테스트"); // String test_env = System.getenv("TEST_ENV");
} // Assumptions.assumingThat(test_env.equals("KIM"), () -> {
// System.out.println("env_kim");
// @Disabled : 모든 테스트 실행 시 테스트 제외 // Study study = new Study(10);
@Test // assertTrue(study.getLimit() > 0, () -> "limit 는 0보다 커야한다.");
@Disabled // });
void create2() { //
System.out.println("create2 테스트"); // Assumptions.assumingThat(test_env.equals("LEE"), () -> {
} // System.out.println("env_lee");
// Study study = new Study(10);
// assertTrue(study.getLimit() > 0, () -> "limit 는 0보다 커야한다.");
// });
// }
//
// @Test
// @DisplayName("assumeTrue test")
// void test_5() {
// String test_env = System.getenv("TEST_ENV");
// System.out.println(test_env);
// Assumptions.assumeTrue("kim".equalsIgnoreCase(test_env));
//
// Study study = new Study(10);
// assertTrue(study.getLimit() > 0, () -> "limit 는 0보다 커야한다.");
// }
//
// @Test
// @DisplayName("assertTimeout test")
// void test_4() {
// assertTimeoutPreemptively(Duration.ofMillis(100), () -> {
// Thread.sleep(300);
// new Study(10);
// });
//
// // assertTimeout( 시간, 실행구문 )
// // 실행 구문이 끝날 때 까지 기다렸다가 결과를 출력한다.
// assertTimeout(Duration.ofMillis(100), () -> {
// Thread.sleep(300);
// new Study(10);
// });
// }
//
// @Test
// @DisplayName("assertThrows test")
// void test_3() {
// // 리턴 값은 해당 예외 타입이다.
// IllegalArgumentException exception =
// assertThrows(IllegalArgumentException.class, () -> new Study(-10));
//
// // 에러 메시지 확인도 가능하다
// assertEquals("limit은 0보다 커야 한다.", exception.getMessage());
// }
//
// @Test
// @DisplayName("assertAll test")
// void test_2() {
// Study study = new Study(-10);
//
// assertAll(
// () -> assertTrue(study.getLimit() > 0, "스터디 최대 참석 가능 인원은 0보다 커야 한다."),
// () -> assertEquals(StudyStatus.DRAFT, study.getStatus(), "스터디를 처음 만들면 status가 DRAFT 이어야 한다.")
// );
// }
//
// @Test
// @DisplayName("assertTrue test")
// void test_1() {
// Study study = new Study(10);
// // assertTrue( 조건, 실패시 출력 메시지 )
// assertTrue(study.getLimit() > 0, "스터디 최대 참석 가능 인원은 0보다 커야 한다.");
// }
//
// @Test
// @DisplayName("assertEquals test")
// void test() {
// Study study = new Study();
// // assertEquals( 기대값, 실제값, 실패시 메시지 )
//
// assertEquals(StudyStatus.DRAFT, study.getStatus(), "스터디를 처음 만들면 status가 DRAFT 이어야 한다.");
// }
//
// @Test
// void create_new_study() {
// Study study = new Study();
// assertNotNull(study);
// System.out.println("create 테스트");
// }
//
// @Test
// @DisplayName("스터디 생성하기!! 💖")
// void create_new_study_2() {
// System.out.println("create1 테스트");
// }
//
// // @Disabled : 모든 테스트 실행 시 테스트 제외
// @Test
// @Disabled
// void create2() {
// System.out.println("create2 테스트");
// }
// //
// /** // /**
// * 모든 테스트 실행 전에 한번 실행 // * 모든 테스트 실행 전에 한번 실행

View File

@@ -31,7 +31,7 @@ public class OrderService {
Member member = memberRepository.findById(memberId).get(); Member member = memberRepository.findById(memberId).get();
Item item = itemRepository.findOne(itemId); Item item = itemRepository.findOne(itemId);
// 배송정보 생성 // 배송정보 생성
Delivery delivery = new Delivery(); Delivery delivery = new Delivery();
delivery.setAddress(member.getAddress()); delivery.setAddress(member.getAddress());