Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@TestFactory does not work with QuarkusUnitTest #46473

Closed
masecla22 opened this issue Feb 25, 2025 · 1 comment · Fixed by #46474
Closed

@TestFactory does not work with QuarkusUnitTest #46473

masecla22 opened this issue Feb 25, 2025 · 1 comment · Fixed by #46474
Labels
area/testing kind/enhancement New feature or request
Milestone

Comments

@masecla22
Copy link
Contributor

masecla22 commented Feb 25, 2025

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.

@masecla22 masecla22 added the kind/bug Something isn't working label Feb 25, 2025
@geoand
Copy link
Contributor

geoand commented Feb 25, 2025

Thanks for reporting.

QuarkusUnitTest is meant for internal testing of extensions themselves and as we have never had the need to use @TestFactory, we are very unlikely to make this happen.
If someone however wants to work it, the contribution will be very welcome.

@geoand geoand added kind/enhancement New feature or request and removed kind/bug Something isn't working labels Feb 25, 2025
@quarkus-bot quarkus-bot bot added this to the 3.21 - main milestone Feb 26, 2025
@gsmet gsmet modified the milestones: 3.21 - main, 3.19.2 Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants