So I've found that SpringBootTest allows injection of properties into test files so that the data in the test file can be overwritten so that production data in the properties file such as:
properties file
data.test1 = Production data 1
data.test2 = Production data 2
Can be overwritten with test data in the test file such as:
test file
@SpringBootTest(properties = {
"data.test1=Test data 1",
"data.test2=Test data 2"})
My issue is that I have lists in my properties file. Is there any way I can inject a list into the SpringBootTest properties attribute like the data below?
properties file with list
data-list:
- id: 1
data: Prod data 1
other-data: Other prod data 1
- id: 2
data: Prod data 2
other-data: Other prod data 2
CodePudding user response:
there are 2 ways:
1: You can override like this
@SpringBootTest(properties = {
"data-list[0].id=1",
"data-list[0].data=data",
"data-list[0].other-data=data",
"data-list[1].id=1",
"data-list[1].data=data",
"data-list[1].other-data=data"})
2: under test folder create a resources folder and override application.properties or yaml file , Spring boot test wil pick overdried file instead of your main app file