We want to introduce property-based testing into our Quarkus project, preferably with jqwik. We already got numerous test cases using junit jupiter. We also use CDI in out test cases.
Getting jqwik running in a small Quarkus example project went well, so I wanted to write some properties in out big project. jqwik is running, however, the @Property
, @Example
and @Provider
methods do not have access to the injected bean (as in: the injected bean is Null, TreeRepository
in the example below). Same for ArbitrarySupplier
subclasses. If I replace the @Example
with a @Test
the referring test can access the bean and the test passes.
My first guess is that this has something to do with the jqwik lifecycle. I did not find enough information about how (and if?) jqwik integrates with injection. How do I get this running?
In the example I expect treeRepository to be an instance of TreeRepository (the class is @ApplicationScoped
). Instead it is null, except for in the method with the @Test
annotation.
@QuarkusTest
class MyTestClass {
@Inject
TreeRepository treeRepository;
@Test
void testSimple() {
final Collection<Tree> trees = this.treeRepository.getTrees() // works
assertThat(trees).isNotEmpty();
}
@Example
void testSimple() {
final Collection<Tree> trees = this.treeRepository.getTrees() // does not work
assertThat(trees).isNotEmpty();
}
@Property
void treesHaveLeaves(@Forall("tree") Tree tree) { // does not work
assertThat(tree.getLeaves()).isNotEmpty();
}
Arbitrary<Tree> tree() {
final Collection<Tree> trees = this.treeRepository.getTrees(); // does not work
return Arbitraries.of(trees);
}
}