Are there any tools which generate Arbs from class...
# kotest
n
Are there any tools which generate Arbs from classes? Maybe there were some ideas to create such generator?
k
n
Kotest Arbs
Maybe this is close to what you're thinking?
If you are thinking of "More general arbs" then maybe this https://kotest.io/docs/proptest/property-test-extra-arbs.html is what you were thinking
n
Sometimes I would need to manually adjust generated Arb
My use case is that I create data class and every time I need to write manually Arb for it
l
Are you doing it through using
bind
?
n
yes
l
Then I think there is no such tool. You'd like to select your data class and say "Generate me the scaffold for a custom Arb that I can modify"
Or something like that?
n
exactly something like that
l
Then I don't think we have it. It would be a good idea for https://github.com/kotest/kotest-intellij-plugin !
e
You can manipulate the arb used for one of the parameters or types. Is that not sufficient?
I see that we haven’t yet released support to so it by parameter. Slated for 5.9. https://kotest.io/docs/next/proptest/reflective-arbs.html
a
I had an idea a while ago to generate arbs from
@Serializable
classes https://kotlinlang.slack.com/archives/CT0G9SD7Z/p1647451898560189
n
Reflective Arbs looks great but I'm almost not use ``checkAll`/`forAll`` in my tests. Instead I have Arbs for every class and use them in every test. Very often I need to use custom Arbs instead of using defaults, instead of
Arb.string()
I need to use `Arb.alphanumeric()`or positiveInt()/int() with Reflective Arbs I would have problem with this in many places because they won't know what exactly kind of Arb is needed.
s
I like the idea of the plugin being able to generate an arb for you, so you can then tweak it manually after.
s
@nacyolsa Perhaps the library I maintain would be helped. It is called Fixture Monkey. It is also the third party extension of kotest. It provides KotestPlugin for generating a custom
Arb
. It can generate an
Arb
instance like
Reflective Arbs
does, customizing the property with
Arb
or any other type. It is the example below.
Copy code
class StringObject(val string: String)

val arb = FixtureMonkey.builder()  
    .plugin(KotestPlugin())  
    .plugin(KotlinPlugin())  
    .build()
    .giveMeArb<StringObject> { setArb(StringObject::string, Arb.zipcodes()) }
👍 2
n
Thanks @Skel, I will check it.
s
@Skel that is a really nice project
❤️ 1
l
it's already listed on third-party extensions. Cool
❤️ 1
n
@Skel I started using your cool project and I have one question. Let's say I have the following class
Copy code
data class A(val id: Int, val assignments: List<Int>)
How can I configure FixtureMonkey to put
id
into
assignments
? I mean FixtureMonkey generates
id
and puts it into ``assignments`` without generating it again with random number.
s
@nacyolsa Sorry for the late reply. I checked Slack now. In that case, You can use
thenApply
API.
Copy code
FixtureMonkey.builder()
    .plugin(KotlinPlugin())
    .build()
    .giveMeBuilder<A>()
.minSizeExp(A::assignments, 1)
.thenApply { a, builder ->
    builder.setExp(A::assignments[0], a.id)
}
.sample()
If you do not want to use this API again, then check out
register
option in FixtureMonkeyBuilder. If you have additional questions, please ask on the GitHub issue!