-
Couldn't load subscription status.
- Fork 3k
Description
Describe the bug
When a JUnit TestFactory includes an @Inject mock service bean initialisation works properly for normal @BeforeEach and @Test annotated methods, but tests executed with @TestFactory have the mock service uninitialised.
Expected behavior
The @Inject bean is initialized correctly during @TestFactory execution.
Actual behavior
The @Inject mock bean fails to be initialized and is thus null.
How to Reproduce?
public class SimpleBeanTestFactoryTest {
@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(SimpleBean.class)
.addAsResource(new StringAsset("simpleBean.baz=1"), "application.properties"));
@Inject
SimpleBean simpleBean;
@TestFactory
public List<DynamicTest> testBeanInsideFactory() {
return List.of(
DynamicTest.dynamicTest("test 1", () -> {
assertNotNull(simpleBean);
}),
DynamicTest.dynamicTest("test 2", () -> {
assertEquals(1, 1);
}));
}
}Output of uname -a or ver
Linux MattsDevMachine 6.8.0-52-generic #53~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Jan 15 19:18:46 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
Output of java -version
openjdk version "21.0.6" 2025-01-21 OpenJDK Runtime Environment (build 21.0.6+7-Ubuntu-122.04.1) OpenJDK 64-Bit Server VM (build 21.0.6+7-Ubuntu-122.04.1, mixed mode, sharing)
Quarkus version or git rev
aadb627 (HEAD at time of writing)
Build tool (ie. output of mvnw --version or gradlew --version)
Quarkus bundled mvnw
Additional information
A similar issue happened in #8004, and was fixed in #8066. I have ported the fix, I can confirm it works, and will be making a PR shortly.