I want to create a test case for a class Foo. That class Foo gets an instance of Bar injected; however, there are different implementations of Bar, and the decision which one should be used depends on a config property. (The technical implementation is a producer method that produces instances of Bar. This producer method gets the config property injected and uses it to decide which implementation to use.)
I can achieve that by creating separate test classes for the different behavior of Foo (which depends on the injected Bar instance) and annotating each of them with a different test profile. These test profiles could provide the configuration such that the different implementations of Bar will be injected.
However, ideally, I want to have the tests in a single test class FooTest. Since the @TestProfile annotation is only allowed for classes, I tried using nested test classes like this:
@QuarkusTest
class FooTest {
@Inject Foo foo;
@Nested
@TestProfile(ProfileA.class)
class TestForImplementationA {
@Test
void testSomething() {
foo.doSomething();
}
}
@Nested
@TestProfile(ProfileB.class)
class TestForImplementationB {
@Test
void testSomething() {
foo.doSomething();
}
}
}
Unfortunately, the test profiles do not seem to be taken into account since I end up with an error that the config property is missing:
The config property barType is required but it could not be found in any config source
Is there any way to achieve what I want, or do I have to stick to the separate test classes?
PS: An example project can be downloaded from https://www.dropbox.com/s/qn3mp4ls32d694a/quarkus-test.zip?dl=0