Reputation: 223
I wanna override the value of a resource in a test:
@SpringBootConfiguration
public class MyExampleConfig {
@Value("classpath:my-example-resource.yml")
private Resource myExampleResource;
}
Does anybody know how I could override the value "classpath:my-example-resource.yml"in my test?
Upvotes: 0
Views: 1117
Reputation: 300
You can use create test configuration (ApplicationTest
) with test .properties
or .yml
in test package and then use it in your tests
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = ApplicationTest.class)
public class Test {
@Test
public void test() throws Exception {
//some code
}
}
Upvotes: 1
Reputation: 51
You can have a separate application.properties file for your test package under resources, and you can define a key value pair i.e :
classpath=classpath:my-example-resource.yml
in this file and use in the code as follows
@Value("${classpath}")
private String classpath;
Upvotes: 1
Reputation: 3471
If you're running @SpringBootTest you can use this annotations:
@RunWith(SpringRunner.class)
@SpringBootTest(properties = {
"key=value",
"key=value"
})
They will override default ones.
Upvotes: 1