junit-quickcheck icon indicating copy to clipboard operation
junit-quickcheck copied to clipboard

Globally configure generator

Open Allsimon opened this issue 6 years ago • 3 comments

I'm looking for a way to globally configure a generator.

For example, I want every LocalDateTime in every POJO to be between 2000/2100.

Is it possible without rewriting every generators for those POJO ?

Allsimon avatar Apr 05 '19 12:04 Allsimon

@Allsimon Thanks for bringing this up. Currently there is no such feature. Generators are configured for each use via some set of configuration annotations they support. For example, the LocalDateTimeGenerator can accept an @InRange marker to specify an interval. I'm hoping to make this a little less cumbersome by allowing them to be collected on a meta-annotation, if I can find time to get to #173.

I think what you're asking for is very useful. Do you have a particular strategy in mind?

pholser avatar Apr 05 '19 15:04 pholser

What kind of API are you planning to implement with #173 ?

I was thinking about GeneratorConfiguration chaining, something looking like this:

@From(MoneyGenerator.class)
@Children(class = Integer.class, configuration = Positive.class)
@Children(class = Double.class, configuration = CustomConf.class)
public @interface SmallChange {
}

Allsimon avatar Apr 08 '19 08:04 Allsimon

@Allsimon My intent behind #173 is to be able to find @Property as a meta-annotation and/or on enclosing elements, such as a class, package, or module (to allow for configuration at greater scope than individual property methods); and to find configuration annotations for a parameter as meta-annotations deeper than one level. I don't anticipate changing how programmers write tests with this change. Does that help?

pholser avatar Apr 16 '19 14:04 pholser