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

QuarkusTestResource with restrictToAnnotatedClass inject for @Nested classes #26639

Closed
stephan-strate opened this issue Jul 10, 2022 · 1 comment · Fixed by #26646
Closed
Labels
area/testing kind/bug Something isn't working
Milestone

Comments

@stephan-strate
Copy link
Contributor

Describe the bug

When QuarkusTestResource is configured to be restrictToAnnotatedClass, it restarts for nested classes annotated with @Nested. This is also the case for QuarkusTestResourceConfigurableLifecycleManager, which apply restrictToAnnotatedClass automatically.

@QuarkusTest
@QuarkusTestResource(value = DummyTestResource.class, restrictToAnnotatedClass = true)
public class DummyNestedTest {

    @InjectDummyString
    String bar;

    @Test
    public void testBar() {
        Assertions.assertEquals("bar", bar); // this assertion works
    }

    @Nested
    class NestedTestClass {

        @Test
        public void testBar() {
            Assertions.assertEquals("bar", bar); // this assertions fails
        }
    }
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface InjectDummyString {
}
public class DummyTestResource implements QuarkusTestResourceLifecycleManager {

    @Override
    public Map<String, String> start() {
        return null;
    }

    @Override
    public void stop() {

    }

    @Override
    public void inject(TestInjector testInjector) {
        testInjector.injectIntoFields("bar", new AnnotatedAndMatchesType(InjectDummyString.class, String.class));
    }
}

Expected behavior

QuarkusTestResource configured with restrictToAnnotatedClass=true should not restart for nested classes annotated with @Nested.
Or, should be capable of injecting fields into the parent class.

Actual behavior

QuarkusTestResource configured with restrictToAnnotatedClass=true restarts for nested classes and can not inject fields located in the parent class.

How to Reproduce?

Reproducer: reproducer.zip

How to reproduce: Execute the tests.

The reproducer introduces a QuarkusTestResourceLifecycleManager which injects the string "bar" using the @InjectDummyString annotation.
The DummyNestedTest shows, that the string is actually null in a nested class annotated with @Nested. Also you can see, that Quarkus is restarting for the nested class.

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.10.2

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@geoand
Copy link
Contributor

geoand commented Jul 11, 2022

@Sgitario do you want to take a look at this one?

@quarkus-bot quarkus-bot bot added this to the 2.12 - main milestone Jul 19, 2022
@gsmet gsmet modified the milestones: 2.12 - main, 2.11.0.Final Jul 19, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jul 19, 2022
michelle-purcell pushed a commit to michelle-purcell/quarkus that referenced this issue Jul 20, 2022
@stephan-strate stephan-strate changed the title QuarkusTestResource with restrictToAnnotatedClass restarts for @Nested classes QuarkusTestResource with restrictToAnnotatedClass inject for @Nested classes Aug 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants