목차

SpringBoot Test

@SpringBootTest

@ExtendWith(SpringExtension.class) 는 SpringBoot 2.1 부터 @SpringBootTest 와 그 하위 애노테이션(@DataJpaTest 등)에 기본 내장돼 있으므로 테스트 클래스에 지정할 필요가 없다.

@SpringBootApplication 클래스 탐지

테스트용 프라퍼티 지정

@SpringBootTest(properties = {"some.username=user", "some.password=pwd"},
                webEnvironment = SpringBootTest.WebEnvironment.NONE)

Context Cache

# 32mb 기본값
spring.test.context.cache.maxSize=32

@TestConfiguration

spring.main.allow-bean-definition-overriding=true

Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

해결 1

@SpringBootTest(classes = MyServiceConfig.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
@EnableAutoConfiguration
class MyApplicationTests {
}

해결 2

@SpringBootTest(classes = SpringBootTestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
class MyApplicationTests {
}

@TestProperties

@TestPropertySource(locations="classpath:test.properties")
public class ExampleApplicationTests {
 
}
 
 
You can use @TestPropertySource
 
@TestPropertySource(
    properties = {
        "some.username=validate",
        "some.password=false"
    }
)

@WebFluxTest

참조