How can I define some specific property for testing that is a list and not just a string?
The documentation explains, how to do with string, but I can't set the value to a list of strings.
application.yml
items:
- "Item 1"
- "Item 2"
Test file:
@MicronautTest(environments = ["test"])
class MyTest {
@Test
@Property(name = "items", value = "Item 1,Item 2") // this does not work
fun justWithOneItem() {
// ...
}
}
On the actual code, this works (as documented here)
Project file:
@Singleton
class SomeClass {
@set:Inject
@setparam:Property(name = "items")
var items: List<String>? = null
// ...
}
I know that I can create an application-test.yml and do
@MicronautTest(environments = ["test"])
class MyTest {
// ...
}
But I would rather prefer to set it programmatically instead of creating a new env/yaml file.
I think you have 2 options:
Use @Property(name = "items[0]", value = "Item1") and @Property(name = "items[1]", value = "Item2")
Change your test to implement TestPropertyProvider and provide the config via the returned map
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With