I'm developing an app (Java) and there is a test that it fails me. This mistake is because I want to read a value that it's in a properties file, but this value is null however If I execute my app skipping the tests, it works ok, it reads the value of the properties file without problem, Do I have to do something different to read this property in test package?
My test class
@Test
public void shouldBeControllerInitial() {
String index = initController.init();
assertEquals("Should be same to the index, it's main page", INDEX,
index);
}
My controller class
@Controller
@RequestMapping(value = "/")
public class InitController {
@Value("${path.index}")
private String index;
@RequestMapping(method = RequestMethod.GET)
public String init() {
return index;
}
}
My config class
@Configuration
@PropertySource("classpath:/path.properties")
public class Config {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer(){
return new PropertySourcesPlaceholderConfigurer();
}
error message
java.lang.AssertionError: Should be same to the index, it's main page
expected:<index> but was:<null> ...
Can anyone help ?