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

Repeatable Annotation-based test resources #31359

Closed
scrocquesel opened this issue Feb 22, 2023 · 2 comments · Fixed by #31383
Closed

Repeatable Annotation-based test resources #31359

scrocquesel opened this issue Feb 22, 2023 · 2 comments · Fixed by #31383
Labels
area/testing kind/enhancement New feature or request
Milestone

Comments

@scrocquesel
Copy link
Contributor

Description

Currently, Annotation-based test resources are not repeatable.
I would like to be able to do somehting like

    @Test
    void testAnnotationBased() {
        TestResourceManager manager = new TestResourceManager(RepeatableAnnotationBasedTestResourcesTest.class);
        manager.init("test");
        Map<String, String> props = manager.start();
        Assertions.assertEquals("value", props.get("annotationkey1"));
        Assertions.assertEquals("value", props.get("annotationkey2"));
    }

    public static class AnnotationBasedQuarkusTestResource
            implements QuarkusTestResourceConfigurableLifecycleManager<WithAnnotationBasedTestResource> {

        private String key;

        @Override
        public void init(WithAnnotationBasedTestResource annotation) {
            this.key = annotation.key();
        }

        @Override
        public Map<String, String> start() {
            Map<String, String> props = new HashMap<>();
            props.put(key, "value");
            return props;
        }

        @Override
        public void stop() {

        }
    }

    @QuarkusTestResource(AnnotationBasedQuarkusTestResource.class)
    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.TYPE)
    @Repeatable(WithAnnotationBasedTestResource.List.class)
    public @interface WithAnnotationBasedTestResource {
        String key() default "";

        @Target(ElementType.TYPE)
        @Retention(RetentionPolicy.RUNTIME)
        @interface List {
            WithAnnotationBasedTestResource[] value();
        }

    }

    @WithAnnotationBasedTestResource(key = "annotationkey1")
    @WithAnnotationBasedTestResource(key = "annotationkey2")
    public static class RepeatableAnnotationBasedTestResourcesTest {
    }

Implementation ideas

No response

@scrocquesel scrocquesel added the kind/enhancement New feature or request label Feb 22, 2023
@scrocquesel
Copy link
Contributor Author

TestManager must discover the content annotation. I have something working with help of a @QuarkusTestResourceRepeatable annotation on the containing annotation type. If the design is accepted, I will open a PR.

    @QuarkusTestResource(AnnotationBasedQuarkusTestResource.class)
    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.TYPE)
    @Repeatable(WithAnnotationBasedTestResource.List.class)
    public @interface WithAnnotationBasedTestResource {
        String key() default "";

        @Target(ElementType.TYPE)
        @Retention(RetentionPolicy.RUNTIME)
        @QuarkusTestResourceRepeatable(WithAnnotationBasedTestResource.class)
        @interface List {
            WithAnnotationBasedTestResource[] value();
        }
    }

@geoand
Copy link
Contributor

geoand commented Feb 23, 2023

Sounds good!

geoand added a commit that referenced this issue Feb 28, 2023
Add support for repeatable annotation-based test resources
@quarkus-bot quarkus-bot bot added this to the 3.0 - main milestone Feb 28, 2023
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.

2 participants