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

Support for non-mock @ConfigMapping in @QuarkusComponentTest #36373

Closed
yrodiere opened this issue Oct 10, 2023 · 0 comments · Fixed by #36389
Closed

Support for non-mock @ConfigMapping in @QuarkusComponentTest #36373

yrodiere opened this issue Oct 10, 2023 · 0 comments · Fixed by #36389
Labels
area/testing kind/enhancement New feature or request
Milestone

Comments

@yrodiere
Copy link
Member

Description

It would be nice if config mappings (@ConfigMapping-annotated interfaces) could be supported in @QuarkusComponentTest, either by default or as an opt-in feature.

Currently they seem to always be mocked, while I'd like them to be handled as they would in a normal application.

For example, if I have a component like this:

@ApplicationScoped 
public class Foo {

    @Inject
    Charlie charlie; 

    @Inject
    FooConfig config;

    @ConfigMapping(prefix = "foo")
    interface FooConfig {
        boolean bar();
    }

    public String ping() {
        return config.bar() ? charlie.ping() : "nok";
    }
}


And a test like this:

@QuarkusComponentTest 
@TestConfigProperty(key = "foo.bar", value = "true") 
public class FooTest {

    @Inject
    Foo foo; 

    @InjectMock
    Charlie charlieMock; 

    @Test
    public void testPing() {
        Mockito.when(charlieMock.ping()).thenReturn("OK"); 
        assertEquals("OK", foo.ping());
    }
}

... then the test won't pass because FooConfig is always injected as a mock, and as a result config.bar() returns false by default.

Using new QuarkusComponentTestExtension(Foo.FooConfig.class) doesn't seem to help.

Implementation ideas

Quote from @mkouba (taken out of context, as all good quotes are):

it should be doable ;-)

@yrodiere yrodiere added kind/enhancement New feature or request area/testing labels Oct 10, 2023
mkouba added a commit to mkouba/quarkus that referenced this issue Oct 11, 2023
@quarkus-bot quarkus-bot bot added this to the 3.6 - main milestone Oct 11, 2023
holly-cummins pushed a commit to holly-cummins/quarkus that referenced this issue Feb 8, 2024
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.

1 participant