0

I am trying to write a Springboot end point unit test using Mockito. System failed to initialize the placeholder during test execution context. Could you please help me to understand where I am going wrong?

@SpringJUnitWebConfig
@ContextConfiguration(classes=MockLocationsController.class)
@TestPropertySource(properties = {
        "version.v1=v1",    
    })
public class MockLocationsControllerTest {

}

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'version.v1' in value "/api/${version.v1}"

darkDragon
  • 455
  • 3
  • 12
  • Possible duplicate of https://stackoverflow.com/questions/20244696/could-not-resolve-placeholder-in-string-value – Vinnie Nov 27 '19 at 17:21

1 Answers1

0

By providing a custom @ContextConfiguration you have created a limited Spring Test context which most likely doesn't have PropertyPlaceholderConfigurer bean. Without that bean property placeholders are not resolved.

Normally Spring Boot tests for the web layer with mocking are declared with @WebMvcTest which gives you minimal working setup with PropertyPlaceholderConfigurer.

@SpringJUnitWebConfig
@WebMvcTest(MockLocationsController.class)
@TestPropertySource(properties = {
        "version.v1=v1",    
    })
public class MockLocationsControllerTest {

}
Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111