Reputation: 127
How can I make Spring create an application context using a specific properties file made for testing purposes when using @SpringBootTest rather than using the standard application.properties?
Thanks in advance
Upvotes: 1
Views: 120
Reputation: 130927
You could create an application.properties
file (or YAML variant) under src/test/resources
.
Alternatively, you can define properties for test in the @TestPropertySource
annotation:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@TestPropertySource(
properties = {
"foo.bar: value",
"fiz.biz: value"
})
public class FooTest {
...
}
This approach is equivalent to defining the properties the @SpringBootTest
annotation:
@RunWith(SpringRunner.class)
@SpringBootTest(
webEnvironment = WebEnvironment.RANDOM_PORT,
properties = {
"foo.bar: value",
"fiz.biz: value"
})
public class FooTest {
...
}
Upvotes: 1