If I do ```someArb.take(10).toList()``` and then f...
# kotest
d
If I do
Copy code
someArb.take(10).toList()
and then feed it to data test's
forAll
it only makes me one test 🤕?
s
there's 200 data tests now
which one are you using
d
Copy code
suspend fun <T : Any> ContainerContext.forAll(ts: List<T>, test: suspend (T) -> Unit)
s
so the new one from 4.5+
d
4.6
s
what is .toList doing
is it making a list of t, or a list of a single element of list(t)
d
I guess converting the sequence from arb's take to a list...?
s
here is a funky example
Copy code
withData("p", "q") { a ->
      withData(listOf("r", "s")) { b ->
         withData(sequenceOf("x", "y")) { c ->
            a + b + c shouldHaveLength 3
            results.add(a + b + c)
         }
      }
   }
so it should all be working
d
I don't have withData...? I think I might have some kind of caching problem...
But Intellij shows me:
s
its in
kotest-framework-datatest
but that should be coming in automatically
d
s
yeah its not
damn that's an oversight
I'd add that module yourself
the DD testing is way better now
it does proper nesting and everything
d
Well still the same problem... still only have one sample generated...
s
what if you do
withData(listOf(1,2) ){ a -> }
d
Puzzling, I have to step out right now, but I tried that (using arb to generate to singles into a list) and still got one test... I'm using instancePerLeaf and
it
inside the withData block...
s
try pasting it in exactly what I put, just to rule out the data test framework
instance per leaf might be the issue
yes now I think about it, it definitely is
d
But I need it so that my test setup can be reinitialized, is it supposed to work?
s
not for data tests
as they're dynamic so it can't find them again on the next pass
d
Well at least it should fail with a proper error message?
s
agreed
d
PerTest would still work with data tests?
If so, it could be suggested as a replacement in the error.
s
no that won't work either probably
just single instance
d
Oh... Then it might be nice to have some kind of memoized construct like in spek? To reinitialize setup, since that's one of the reasons why i use InstancePerLeaf all the time
s
it wouldn't help with data tests
If you want to create a ticket, I will look into what can be done for 5.0
d
Ok, I'll try to remember tomorrow when I get to work, thanks!
c
if each context invocation uses the same random seed it would always create the same tests. that could be an easy fix.
d
@sam Does
beforeTest
work with data tests?
s
Yes
d
kotlin.UninitializedPropertyAccessException: lateinit property requestSequence has not been initialized
Copy code
lateinit var requestSequence: Sequence<InitializeAccountRequest>

init {
    isolationMode = IsolationMode.SingleInstance

    describe("Initialization of account") {
        beforeTest {
            registrationState = setupRegistrationState(RegistrationState.arbValid().single()) {
                requestSequence = InitializeAccountRequest.arb(
                    odooDevice!!.id, oroAccount!!.id
                ).take(10)
            }
        }

        withData(requestSequence) { request ->
s
The nested before test might be causing a bug
It should work. I'm afk atm will check soon
d
Yeah, when I take it out of describe it works...
s
Probably easy fix
d
Can I use beforeContainer to setup before each data set?
s
Yes
d
Oh boy! I suppose that withData grabs all the values from the sequence BEFORE it runs the test?
Since it seems that when I assert the state of the repos in the lateinit var already change... and they all fail.
So beforeContainer doesn't help at all in such a case...
And should withData contain `it`s or is it a test in itself @sam?
s
withData makes the tests for you
its basically like doing forEach with a test / it inside
d
Oh... so asserting multiple named assertions isn't possible then... I usually put the Arrange and Act in a
context
and Assert in a bunch of `it`s to verify multiple assertions on the state coming out of the Act.
s
you can add further nests tests
Copy code
withData(listOf(1,2)) { a ->

   context("set me up") { 
   }

    it("run me") {

    }
}
d
So basically the same as:
Copy code
it("..") {
   context("...") {
      it("...") {
         ...
      }
   }
}
and that works?
👍🏻 1
s
well not tried it but I don't see why it wouldn't
d
only when surrounded by
context
? Also, maybe that's what caused my previous problems... https://kotlinlang.slack.com/archives/CT0G9SD7Z/p1621951379106600?thread_ts=1621871119.093600&amp;cid=CT0G9SD7Z
the beforeContainer might not be doing the initialisation properly when doing that...
And w/o nesting (no it inside withData), I get a funny <init> on a failing test...
Using #strikt for assertions that seem to work nicely with kotest so far...
s
yes if you wanted to use them
Kotest's assertions are richer
you can use both together
d
But why the <init>?
s
you might have an error outside of the test, I don't knnow
and yes withData will materialize the full list
d
Which makes it impossible to use lateinit vars in the class's context with SingleInstance... and still make sure they have the same state when asserting....
s
I think you can do what you want
d
I'm a bit stuck with the setup part here... 🤕
s
Do you have a full example
d
I'll try to DM part of it...