I'm trying to create a Unit Test with Spring.
Test class:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {MyConfig.class})
public class MyTest{
@Test
public void ...
}
Class to load:
@ConfigurationProperties()
@PropertySource("config/myConfig.properties")
@Component
public class MyConfig {}
Exception:
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [de.db.sus.converter.fia.business.algorithm.config.FiaConverterConfig]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/config/myConfig.properties]
I have found resources for web applications and/or xml based configurations, but wasn't apply to transfer them.
If I would start the application with @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)the properties get loaded. But I can't start the whole application for every Unit test.
I have verified that the file exists in the directory test/resources/config/