0

We have a bunch of generators specified in a class.

class MyUsefulGenerators {

    @Provide 
    public Arbitrary<String> someDomainSpecificThing() {
        ...
    }
}

They're broadly useful, so I'd like to be able to use them in different test classes other than where they're specified. For example:


class MyTestClass {

    @Property
    void testThing(@ForAll("someDomainSpecificThing") String thing) {
        ...
    }
}

However, jqwik is unable to discover this Provider since it lives outside of the current class. I can, of course, manually import the provider from the other class and setup a new provider in this one, but that all feels a bit crufty.

Is there a way to directly use a Provider specified in another file?

1 Answers1

1

jqwik's mechanism for provider sharing is called "Domains". There's a whole chapter on it in jqwik's user guide.

In your example you could introduce a domain context class like this:

class MyDomainContext extends AbstractContextBase {
    @Provide 
    public Arbitrary<String> someDomainSpecificThing() {
        /// return whatever
    }
}

and then use the context in your property:

class MyTestClass {

    @Property
    @Domain(MyDomainContext.class)
    void testThing(@ForAll String thing) {
        ...
    }
}
johanneslink
  • 4,877
  • 1
  • 20
  • 37