-
-
Notifications
You must be signed in to change notification settings - Fork 66
Open
Labels
Description
Testing Problem
Here is an example of testing a sealed interface which represents a data type.
class ExampleProperty {
sealed interface JsonValue {
record Text(String text) implements JsonValue {}
record Number(double value) implements JsonValue {}
}
@Property
@Domain(DomainContext.Global.class)
@Domain(JsonDomain.class)
void example(@ForAll @UseType JsonValue jsonValue) {
System.out.println(jsonValue);
}
static class JsonDomain extends DomainContextBase {
@Provide
Arbitrary<JsonValue> jsonValue() {
return Arbitraries.of(JsonValue.class.getPermittedSubclasses())
.flatMap(c -> Arbitraries.forType(c).map(j -> (JsonValue) j));
}
}
}Perhaps this strategy could be attempted by jqwik's @UseType by default?
Discussion
The current behaviour is that generation fails immediately for a sealed interface. Having this as the default behaviour could potentially be worse if it fails to discover/generate some of the subclasses and they get missed in testing?
Reactions are currently unavailable