I want to test small parts of the application that rely on properties loaded with @Autowired and @ConfigurationProperties. I am looking for a solut
You need to annotate your TestConfiguraion with @EnableConfigurationProperties as follows:
@EnableConfigurationProperties
public class TestConfiguration {
@Bean
@ConfigurationProperties(prefix = "test")
public TestSettings settings (){
return new TestSettings();
}
}
Also you only need to include TestConfiguration.class in @ContextConfiguration of you SettingsTest class:
@TestPropertySource(locations = "/SettingsTest.properties")
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = TestConfiguration.class)
public class SettingsTest {
...