inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링 부트 개념과 활용

외부 설정 1부

@TestPropertySource, @SpringBootTest 우선순위 관련 질문드립니다.

3956

황준오

작성한 질문수 8

0

안녕하세요.

@TestPropertySource@SpringBootTest 우선순위 테스트 하다가

궁금한 점이 있어 질문을 남기게 되었습니다.

 

@TestPropertySource(properties = "")
@SpringBootTest(properties = "")

에서는 @TestPropertySource 의 우선순위가 더 높지만,

 

@TestPropertySource(locations = "")
@SpringBootTest(properties = "")

에서는 @SpringBootTest의 우선순위가 더 높은 것이 맞는지요?

 

문서를 확인해보았으나 부족한 영어 능력 탓인지 해당 내용을 찾지 못하였습니다. ㅠㅠ

아래는 제가 했던 Test 코드 입니다.

@TestPropertySource(properties = "from.route=@TestPropertySource")
@SpringBootTest(properties = "from.route=@SpringBootTest")
public class ApplicationTest {
    @Autowired
    private Environment environment;

    @Test
    public void testProperties() {
        assertThat(environment.getProperty("from.route"))
                .isEqualTo("@TestPropertySource");
   }
}

Test 통과합니다.

 

@TestPropertySource(locations = "classpath:/ApplicationTest.properties")
@SpringBootTest
public class ApplicationTest {
    @Autowired
    private Environment environment;

    @Test
    public void testProperties() {
        assertThat(environment.getProperty("from.route"))
                .isEqualTo("@TestPropertySource");
    }
}

Test 통과합니다.

 

@TestPropertySource(locations = "classpath:/ApplicationTest.properties")
@SpringBootTest(properties = "from.route=@SpringBootTest")
public class ApplicationTest {
    @Autowired
    private Environment environment;

    @Test
    public void testProperties() {
        assertThat(environment.getProperty("from.route"))
                .isEqualTo("@TestPropertySource");
    }
}

Test 실패합니다.
 

org.junit.ComparisonFailure:

Expected :"@TestPropertySource"

Actual :"@SpringBootTest"

spring spring-boot java

답변 2

0

황준오

답변 감사합니다.
제가 질문을 제대로 전달하지 못한것 같네요.
제가 테스트한 대로는 우선순위는 다음과 같습니다.
 
@TestPropertySource 의 우선순위가 @SpringBootTest 보다 높다.
하지만, @TestPropertySource(locations="") 의 경우에는 @SpringBootTest 보다 낮다. 입니다.  
 
제가 계속 헛소리하는 건 아닐까 걱정되지만..
@SpringBootTest#properties설정@TestPropertyTest#locations설정 을 계속 덮어버립니다.
 
따라서

우선순위

1. @TestPropertySource#properties 설정

2. @SpringBootTest#properties설정

3. @TestPropertyTest#locations설정

라고 생각되어서 질문을 남기게 되었습니다.

0

백기선

문서에 따르면 우선 순위는 다음과 같습니다.

1. devtools 글로벌 설정

2 @TestPropertySource 애노테이션 설정

3. @SpringBootTest#properties 설정

문서는 여기를 참고하세요.

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config

좋은 질문 주셔서 감사합니다.

자동설정 만들기 1부의 Holoman 관련 문의 드립니다.

0

84

1

라이브러리 개발 예제 강의를 찾습니다 !!!

0

225

2

강의 진행되로 똑같이 했는데 jquery가 실행되지 않았는데

0

310

1

HateOas 가 업데이트가 되어서, "Spring HATEOAS" 코드를 아래처럼 하셔야 될겁니다.

0

364

2

springSecurit jwt에 대해서 질문드립니다.

0

343

1

섹션2 자동설정 부분 질문있습니다.

0

249

1

mongo shell 명령어 대체 mongo -> mongosh

0

1012

1

데이터베이스 마이그레이션 강의에서 질문 있습니다

0

707

0

자동 설정 만들기 2부에서 질문 있습니다

0

413

1

의존성 관리 응용 부분에서 질문 있습니다

0

321

0

Intellij 에서 빈 주입할때 계속 빨간줄이 뜨는데 어떻게 고쳐야 할까요

0

1184

1

자동설정으로 다른 프로젝트 빈 사용(번외질문)

0

363

0

CREATE TABLE 예제 따라하다가 'expected "identifier"; SQL statement:' 오류나는 경우

2

2212

2

junit5 관련하여 질문드립니다.

0

307

2

맨 처음 프로젝트 생성 후 Run 시 에러

0

535

2

외부 설정과 관련된 질문입니다.

0

255

1

test와 runner account.setEmail에 동일한 값 입력

0

323

1

컨트롤러 view 호출

0

265

1

JVM 과 arguments 는 뭔가요???

0

1170

1

pom 테그 에러

0

355

1

안녕하십니까 기선님!!!!! webclient와 비동기관련 질문요청드립니다

0

1554

1

webEnvironment 내장 톰캣

0

228

1

application.yml 파일 분리

0

393

1

안녕하세요 기선님 서블릿 어플리케이션 구조에 대해 질문드립니다

0

281

1