Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provider from domain context cannot be referenced by name #406

Closed
lmartelli opened this issue Nov 8, 2022 · 4 comments
Closed

Provider from domain context cannot be referenced by name #406

lmartelli opened this issue Nov 8, 2022 · 4 comments
Labels

Comments

@lmartelli
Copy link

Testing Problem

import io.kotest.matchers.string.shouldNotHaveLength
import net.jqwik.api.ForAll
import net.jqwik.api.Property
import net.jqwik.api.Provide
import net.jqwik.api.domains.Domain
import net.jqwik.api.domains.DomainContextBase
import net.jqwik.kotlin.api.any

@Domain(MyDomain::class)
class BugTest {
    @Property
    fun fail(@ForAll("customerIds") s: String) {
        s shouldNotHaveLength 0
    }
}

class MyDomain : DomainContextBase() {
    @Provide
    fun customerIds() = String.any().ofMinLength(1)
}

Gives net.jqwik.api.CannotFindArbitraryException: Cannot find an Arbitrary [customerIds] for Parameter of type [@net.jqwik.api.ForAll(value="customerIds", supplier=net.jqwik.api.ArbitrarySupplier$NONE.class) String]

@jlink
Copy link
Collaborator

jlink commented Nov 8, 2022

At first glance it looks like it should work. I’ll have a closer look at it tomorrow.

@jlink jlink added the wontfix label Nov 9, 2022
@jlink
Copy link
Collaborator

jlink commented Nov 9, 2022

At second glance it works as designed :-)
Provider methods from domains are not being looked up by name but by type. That means that all you have to do is:

@Property
fun fail(@ForAll s: String) {
        s shouldNotHaveLength 0
}

If you want, you can apply the domain to a single property:

@Domain(MyDomain::class)
@Property
fun fail(@ForAll s: String) {
        s shouldNotHaveLength 0
}

@jlink jlink closed this as completed Nov 9, 2022
@lmartelli
Copy link
Author

Thanks for the qwik feedback.

However, the purpose of DomainContext being to group arbitrary providers, arbitrary configurators and reporting formats in order to share them, this design leads to a problematic limitation in my opinion. You may want to have different providers for the same type and differentiate using names, and this use case is really cumbersome with the current design. The domain context is only really useful if it has has all the features and the same behaviours as "inline" declarations.

@jlink
Copy link
Collaborator

jlink commented Nov 10, 2022

Domains are not the best choice for re-using general-purpose arbitrary providers.
You may want to look at Arbitrary Suppliers instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants