Spring
[TIL] 231201Spring 통합테스트 Service Test
studymode
2023. 12. 2. 01:37
통합테스트 (Integration Test)
두개 이상의 모듈이나 클래스를 테스트 할 수 있다
모듈 간의 연결에서 발생하는 에러 검증 가능
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) // 서버의 PORT 를 랜덤으로 설정합니다.
@TestInstance(TestInstance.Lifecycle.PER_CLASS) // 테스트 인스턴스의 생성 단위를 클래스로 변경합니다.
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@SpringBootTest에너테이션으로 스프링 실행되게 함(unit test시에는 스프링 실행 안됨)
class ProductServiceIntegrationTest {
@Autowired
ProductService productService;
@Autowired
UserRepository userRepository;
@Autowired사용해 다른 클래스 가져오기
@Test
@Order(1)
@DisplayName("신규 관심상품 등록")
void test1() {
// given
// when
// then
}
@Order로 순서 지정