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

Per-parameter MethodSource analogue for CartesianTest #796

Open
jpenilla opened this issue Dec 13, 2023 · 5 comments
Open

Per-parameter MethodSource analogue for CartesianTest #796

jpenilla opened this issue Dec 13, 2023 · 5 comments

Comments

@jpenilla
Copy link
Contributor

jpenilla commented Dec 13, 2023

A way to provide values for a single parameter from a set of factory methods, similar to @MethodSource for parameterized tests would be nice to have for @CartesianTests. An example of how this might look:

    @CartesianTest
    void testDirectRoundTripStyle(
        @MethodParameterSource("dynamicOps") final DynamicOps<?> dynamicOps,
        @MethodParameterSource({"testStyles", "extraTestStyles"}) final Style style
    ) {
        testDirectRoundTrip(dynamicOps, STYLE_MAP_CODEC.codec(), style);
    }

    static List<DynamicOps<?>> dynamicOps() {
        // ...
    }

    static List<Style> testStyles() {
        // ...
    }

    static List<Style> extraTestStyles() {
        // ...
    }

I've implemented a PoC here, it's currently quite rough and copies a lot of junit internal code. If this is a concept that the maintainers are open to I can look at cleaning it up and opening a PR.

@jpenilla jpenilla changed the title Per-parameter MethodSource analogue for CatesianTest Per-parameter MethodSource analogue for CartesianTest Dec 13, 2023
@Michael1993
Copy link
Member

I've taken a look at your PoC. It could certainly be improved but I think you can go ahead with a PR because this is certainly something we would be interested in.

@Michael1993
Copy link
Member

Hey, could you elaborate how this is different from @CartesianTest.MethodFactory?

@jpenilla
Copy link
Contributor Author

The proposed @CartesianTest.MethodParameterSource is parameter-scoped and provides values for only the annotated parameter. With similar semantics to resolving values as @MethodSource does for @ParameterizedTests.

The existing @CartesianTest.MethodFactory is method-scoped, not parameter-scoped, and requires providing values for all parameters as an ArgumentSets.

The per-parameter nature makes multiple test data more easily composable without needing extraneous methods to combine the values into an ArgumentSets.

@Michael1993
Copy link
Member

Since there is quite a bit of overlap - could you extract the common parts into our internal package (possibly as part of a new Util class)?

@Bukama
Copy link
Member

Bukama commented Dec 21, 2023

Since there is quite a bit of overlap - could you extract the common parts into our internal package (possibly as part of a new Util class)?

Should this be an comment on the draft? :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants