Or, better question, how do I get a "ContainerScop...
# kotest
t
Or, better question, how do I get a "ContainerScope" inside a StringSpec?
s
Use free spec
Which is just nested string spec
t
ok.. Tried funSpec, and then just now Free. The nested contexts aren't running in either.. Tried both intellij and gradle runners
s
Gradle should be fine. I use that myself. Got example code? What about the tests in kotest itself can you run those ?
t
Was about to try a generic test to post.
Copy code
import io.kotest.core.datatest.forAll
import io.kotest.core.spec.style.FreeSpec
import io.kotest.matchers.shouldBe

class ATest:FreeSpec( {
    data class TestData(val number1: Int, val number2: Int, val sum: Int)
    "test" {
        "nested" - {
            forAll(
                TestData(1,2,3),
                TestData(2,2,0),
            ){
                    (a,b,c) -> a+b shouldBe  c
            }
        }
    }
})
using
Copy code
testImplementation("io.kotest:kotest-runner-junit5-jvm:4.3.1")
    testImplementation("io.kotest:kotest-assertions-core:4.3.1")
from my debugger, it doesn't seem to be going inside the nested one. a breakpoint on the forAll never fires
oh...
Copy code
"test" {
  "test" - {
that's subtle.
FunSpec does the same:
Copy code
class ATest:FunSpec( {
    data class TestData(val number1: Int, val number2: Int, val sum: Int)
    test("test") {
        context("nested") {
            forAll(
                TestData(1,2,3),
                TestData(2,2,0),
            ){
                    (a,b,c) -> a+b shouldBe  c
            }
        }
    }
})
That context isn't valid there, and gets 100% ignored
I was using the example under FunSpec which was actually a DescribeSpec. If I just drop the
test
scope, it works as expectd
s
You can't nest context inside test as test is a final scope.
Maybe the DSL could be improved to fix
Copy code
class ATest: FreeSpec() {
    data class TestData(val number1: Int, val number2: Int, val sum: Int)
    "test" - {
            forAll(
                TestData(1,2,3),
                TestData(2,2,0),
            ){
                    (a,b,c) -> a+b shouldBe  c
            }
    }
})
That should work (without testing it)
c
context could just throw if its inside a test
t
Yeah. My only concern would be a subtle error like what I did creep in somehow, and suddenly the tests become no-ops
It's totally working w/ the
"test" -
syntax
and with the FunSpec's
context("name")
s
@christophsturm is right, we should throw errors at runtime for ill defined tests. I'll ticket that up.
t
Awesome. Thanks!