Testing Problem
When using Arbitraries.forType() method, there is NPE exception, when it is used outside of jqwik test runner (i.e. in junit 5 default, jupiter, runner).
Stacktrace:
java.lang.NullPointerException
at net.jqwik.engine.facades.ArbitrariesFacadeImpl.allDefaultsFor(ArbitrariesFacadeImpl.java:196)
at net.jqwik.engine.facades.ArbitrariesFacadeImpl.lambda$defaultFor$3(ArbitrariesFacadeImpl.java:164)
at net.jqwik.engine.properties.arbitraries.LazyArbitrary.generator(LazyArbitrary.java:18)
at net.jqwik.api.Combinators$ListCombinator$1.lambda$generator$0(Combinators.java:697)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
at net.jqwik.api.Combinators$ListCombinator$1.generator(Combinators.java:698)
at net.jqwik.engine.properties.arbitraries.IgnoreGenerationErrorArbitrary.generator(IgnoreGenerationErrorArbitrary.java:18)
at net.jqwik.engine.properties.shrinking.FlatMappedShrinkable.lambda$new$0(FlatMappedShrinkable.java:17)
at net.jqwik.engine.properties.shrinking.FlatMappedShrinkable.generateShrinkable(FlatMappedShrinkable.java:29)
at net.jqwik.engine.properties.shrinking.FlatMappedShrinkable.<init>(FlatMappedShrinkable.java:24)
at net.jqwik.engine.properties.shrinking.FlatMappedShrinkable.<init>(FlatMappedShrinkable.java:17)
at net.jqwik.engine.facades.RandomGeneratorFacadeImpl.flatMap(RandomGeneratorFacadeImpl.java:21)
at net.jqwik.api.RandomGenerator.lambda$flatMap$2(RandomGenerator.java:58)
Test code throwing exception is something like this:
public static UserForTests aUserFromForType() {
return Arbitraries.forType(UserForTests.class).usePublicConstructors()
.generator(0).next(rnd).value();
}
Problem is test engine. I have also one property based test, which is passing ok. Here it is:
@Property
@Report(Reporting.GENERATED)
void justTestOfForTypeThing(@ForAll @UseType UserForTests aPerson) {
System.out.println(aPerson);
}
@Provide
Arbitrary<UserForTests> people() {
return Arbitraries.forType(UserForTests.class).usePublicConstructors();
}
Suggested Solution
I would check, if forType is called in right context (i.e. correct test engine executor) and throw some more informative exception.
Perhaps in DefaultTypeArbitrary constructor would be a nice place. Other imho valid place could be in DomainContextFacadeImpl. Change its static property called currentContext into "static getter" and check for valid value in thread local there.
Discussion
I am not aware if jqwik internal code hierarchy, so not much here from me. I would just suggest to document for jqwik engine in forType javadoc. (I can try to make pull request for this if you like).
Testing Problem
When using
Arbitraries.forType()method, there is NPE exception, when it is used outside of jqwik test runner (i.e. in junit 5 default, jupiter, runner).Stacktrace:
Test code throwing exception is something like this:
Problem is test engine. I have also one property based test, which is passing ok. Here it is:
Suggested Solution
I would check, if forType is called in right context (i.e. correct test engine executor) and throw some more informative exception.
Perhaps in
DefaultTypeArbitraryconstructor would be a nice place. Other imho valid place could be inDomainContextFacadeImpl. Change its static property calledcurrentContextinto "static getter" and check for valid value in thread local there.Discussion
I am not aware if jqwik internal code hierarchy, so not much here from me. I would just suggest to document for jqwik engine in forType javadoc. (I can try to make pull request for this if you like).