I´m trying to configurate new properties for the test, so I created a test config class:
JavaScript
x
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.scheduling.annotation.EnableAsync;
@Configuration
@EnableAsync
@ComponentScan("ar.com.yo")
@PropertySource("test.properties")
public class TestConfig {
}
Properties file is in src/test/resources/test.properties
and in the test class :
JavaScript
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration(classes = TestConfig.class)
public class InsumoServiceTest {
}
when I execute the tests the error is: Failed to parse configuration class [ar.com.yo.myproject.main.TestConfig]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/test.properties]
Advertisement
Answer
It seems that the requested properties can’t be found. I would recommend doing this: is that resolve your problem :
JavaScript
@PropertySource("classpath:test.properties")