jqwik-team / jqwik

Property-Based Testing on the JUnit Platform
http://jqwik.net
Eclipse Public License 2.0
578 stars 64 forks source link

ListArbitrary<T> providers are not selected to resolve List<T> parameters #485

Closed lmartelli closed 6 months ago

lmartelli commented 1 year ago

Testing Problem

A @Provide method in a domain that returns a ListArbitrary<Thing> is not used to generate values for a @ForAll List<Thing>. See https://github.com/jqwik-team/jqwik/compare/main...lmartelli:jqwik:ListArbitrary-provider

Suggested Solution

In net.jqwik.engine.properties.DomainContextBaseProviders.MethodBasedArbitraryProvider#arbitraryType() the actual generic type parameter of ListArbitrary is lost when navigating to the implemented interface Arbitrary.

I am not sure if the mapping can be done in the general case, but it seems safe to say that in the case where there is only one generic type parameter in the class and in the interface, it can be propagated.

I will try to do that.

jlink commented 1 year ago

If you find an easy solution, go ahead.

My recommendation, though: Don't dive too deep into type matching code if there is an easy workaround - just use Arbitrary<List<Thing>> here. There are too many edge cases concerning co- and contravariance that one can easily have one's soul sucked out trying to cover everything. I already lost too many hours of my life in that area :-/

jlink commented 6 months ago

@lmartelli I assume you haven't found a viable solution. Feel free to re-open if I'm wrong.