[spring-boot] @TestPropertySource

이것 저것 테스트 케이스를 만들어 봄봄봄.

# src/test/resources/custom.properties
custom-property-test-is-true=true
custom-property-test-is-false=false
custom-property-test-foo=foo
custom-property-test-2017=2017

테스트 @TestPropertySource의 locations에 classpath를 써 줘야 함.

@RunWith(SpringRunner.class)
@TestPropertySource(locations = "classpath:custom.properties")
public class CustomPropertyTest {

@Value("${custom-property-test-is-true}")
private Boolean isTrue;

@Value("${custom-property-test-is-false}")
private Boolean isFalse;

@Value("${custom-property-test-foo}")
private String foo;

@Value("${custom-property-test-2017}")
private int year;

@Test
public void custom_properties_test() throws Exception {
assertThat(this.isTrue).isTrue();
assertThat(this.isFalse).isFalse();
assertThat(this.foo).isEqualToIgnoringCase("FOO");
assertThat(this.year).isEqualTo(2017);
}
}
Like what you read? Give Logan.81k a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.