-
Notifications
You must be signed in to change notification settings - Fork 64
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
Arbitrary proiders registered under a Domain don't seem to support @ForAll properly #407
Comments
The feature works almost as you expect. Let me explain: To make your example work, you'll have to tell jqwik to use the global context as well. You can do that in one of two ways. @Domain(DomainContext.Global.class)
public class CustomDomain extends DomainContextBase {
@Provide
public Arbitrary<MyType> provideMyType(@ForAll int number) {
return Arbitraries.of(new MyType());
}
} Or at the place where you use the domain: @Domain(DomainContext.Global.class) // alternatively on the test container class
public void shouldMatch(@ForAll MyType myType) {
/* Some testing logic */
} That said, domains are not considered to be the best way for reusing provider methods. And one more thing on using @Provide
public Arbitrary<List<MyType>> provideMyTypes(@ForAll int number) {
return Arbitraries.create(() -> new MyType()).list().ofSize(number);
} If you just want to use @Provide
public Arbitrary<MyType> provideMyType() {
return Arbitraries.integers().map (number -> new MyType(number));
} |
Got it! Sneaky. I see it's in one of the examples on the User guide - but it probably needs to be documented a little better. |
I agree. Will put it on my todo list for the next release. |
Due to some issues in JQwik, we currently have to wrap the provider in a @provide method and call the model. Meaning, everywhere we use the model, we have to define a @provide method. Not ideal - but works for now. For more information on the issue, see: jqwik-team/jqwik#407
Testing Problem
The following code:
This throws an exception complaining that an arbitrary for parameter type
int
cannot be found - something I am assuming should work. At least that is what I would expect.Current Workaround
While not ideal - current workaround is to use inheritance (rather than a Domain annotation) and share the provider that way.
The text was updated successfully, but these errors were encountered: