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

CartesianArgumentsProvider is not intuitive to implement #520

Closed
filiphr opened this issue Sep 12, 2021 · 4 comments
Closed

CartesianArgumentsProvider is not intuitive to implement #520

filiphr opened this issue Sep 12, 2021 · 4 comments

Comments

@filiphr
Copy link
Contributor

filiphr commented Sep 12, 2021

If I am a library developer that would like to implement a CartesianArgumentsProvider I would have to make my class be stateful and I would have to make my implementation implement ArgumentsProvider (even if I don't want to do that).

The current API looks like this:

public interface CartesianArgumentsProvider extends ArgumentsProvider {

    void accept(Parameter parameter);

}

This means that if my implementation is both for @CartesianTest and @ParametrizedTest then I have to have a state in it and implement AnnotationConsumer.

In addition to that there is no way for me to use a CartesianArgumentsProvider without creating an annotation. For example for @ParametrizedTest I can do the following:

class MyTest {

    @ParametrizedTest
    @ArgumentsSource(MyArgumentsProvider.class)
    void myTest(String argument);

}

However, I cannot do something like

class MyTest {

    @CartesianTest
    void myTest(@ArgumentsSource(MyArgumentsProvider.class) String argument);

}

Because @ArgumentsSource is from JUnit jupiter and its target is only ANNOTATION_TYPE and METHDO.

@filiphr
Copy link
Contributor Author

filiphr commented Sep 12, 2021

While working on some tests for PR #519 which is linked to this issue. I came to something which confuses me.

It is

if (!methodSources.isEmpty() && !parameterSources.isEmpty())
throw new ExtensionConfigurationException(
"Providing both method-level and parameter-level argument sources for @CartesianTest is not supported.");

That error makes it like method level argument sources are allowed. However, if we do that it is not working. That can be seen in

return getSetsFromArgumentsSources(parameterArgumentsSources, context);
. Basically only the parameterArgumentsSources are passed to the getSetsFromArgumentsSource. What is the goal here?

@Michael1993
Copy link
Member

There are currently no method-level argument sources for @CartesianTest. In another PR, I hope to add @FactorySource (and perhaps @SingleSource).

@filiphr
Copy link
Contributor Author

filiphr commented Sep 12, 2021

Thanks for the clarification @Michael1993. My changes in PR #519 could actually help with that as well. You could pass each parameter to the method cartesian argument source. That way your custom implementation also has access to the parameter.

@Bukama
Copy link
Member

Bukama commented Sep 12, 2021

Thank you for opening the requested issue. It's more clearer for me now!

@Bukama Bukama closed this as completed in 0bee05d Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants