Is it possible to nest tests in a string spec? If ...
# kotest
e
Is it possible to nest tests in a string spec? If I simply write
Copy code
class TestyMcTestFace : StringSpec({
    "root" {
        "node" {
            1 + 1 shouldBe 2
        }
    }
})
It results in an
InvalidDslException: Cannot add a root test after the spec has been instantiated: node
e
Not in StringSpec, but
FreeSpec
is almost identical but also supports nesting
Copy code
class TestyMcTestFace : FreeSpec({
    "root" - {
        "node" {
            1 + 1 shouldBe 2
        }
    }
})
Note the hyphen for nesting.
e
Thanks
All styles offer the ability to nest tests.
e
yes, that's incorrect as far as I can tell
e
l
There's even a little something in the code to explicitly prevent String Spec from having containers
This is a very old discussion related to Gradle. The original idea was to kill
FreeSpec
and transform it to
StringSpec
+ Containers. However, Gradle doesn't like having a test that is both a
Container
and a
Test
, and thus we are cornered.
Original issue was from BehaviorSpec: https://github.com/kotest/kotest/issues/594
The old gradle issue is still open since 2018: https://github.com/gradle/gradle/issues/4912
@sam and I have one participation or two there already. Feel free to bump it once more xD
e
Thanks