Related: is there a guaranteed execution order of ...
# kotest
l
Related: is there a guaranteed execution order of container/contained tests?
This spec:
Copy code
FreeSpec({
    isolationMode = IsolationMode.InstancePerRoot
    val sut = MyViewModel()

    "1" - {
        println("1")
        ++sut.counter
        println("Counter: ${sut.counter}")

        "1.1" - {
            println("1.1")
            ++sut.counter
            println("Counter: ${sut.counter}")

            "1.1.1" {
                println("1.1.1")
                ++sut.counter
                println("Counter: ${sut.counter}")
            }
        }

        "1.2" - {
            println("1.2")
            ++sut.counter
            println("Counter: ${sut.counter}")

            "1.2.1" {
                println("1.2.1")
                ++sut.counter
                println("Counter: ${sut.counter}")
            }
        }
    }
})

class MyViewModel {

    var counter: Int = 0
}
Prints:
Copy code
1
Counter: 1
1.1
Counter: 2
1.1.1
Counter: 3
1.2.1
Counter: 5
1.2
Counter: 4
So 1.2. is actually printed after 1.2.1
I don't have any parallelism set, I'm on Kotest 6.0 and everything is with default settings (apart from InstancePerRoot).
Or is it just a console artifact, because the counter value is actually increased correctly?
a
this is very similar to this issue, it would be good if you could tell us whether you experience the same as what's described there. As for running your example, when I run it (with the intelliJ plugin) I get:
Copy code
1
Counter: 1
1.1
Counter: 2
1.1.1
Counter: 3
1.2
Counter: 4
1.2.1
Counter: 5
l
I run the test from the gutter icon in Android Studio
Yes, I just tried the attached "My dummy project" from the issue an I get the same (wrong) order of the println() outputs:
Copy code
beforeSpec
context1
given1
and1
when1
then1
then2
when2
afterSpec
I run it from the gutter icon in Android Studio Otter (2025.2.1)
a
interesting, it never occurred to me that Android Studio would have a different order. Will check but unfortunately I don't have much experience with the plugin 🙂
l
It's not an Android Studio problem
It's the gutter icon
a
that being said, when you actually run the test with gradle (which I suspect is what's important for your pipelines etc) you get the right order?
l
When I launch tests from Gradle the order is correct
a
yeah the gutter icon, given by the kotest intellij plugin
l
Copy code
MyClassTests STANDARD_OUT
    beforeSpec
    context1

MyClassTests > Context: a broomstick should be able to be fly and come back on it's own STANDARD_OUT
    given1

MyClassTests > Context: a broomstick should be able to be fly and come back on it's own > a broomstick STANDARD_OUT
    and1

MyClassTests > Context: a broomstick should be able to be fly and come back on it's own > a broomstick > And: and STANDARD_OUT
    when1

MyClassTests > Context: a broomstick should be able to be fly and come back on it's own > a broomstick > And: and > When: I sit on it > Then: I should be able to fly STANDARD_OUT
    then1

MyClassTests > Context: a broomstick should be able to be fly and come back on it's own > a broomstick > And: and STANDARD_OUT
    when2

MyClassTests > Context: a broomstick should be able to be fly and come back on it's own > a broomstick > And: and > When: I don't sit on it > Then: I should be able to fly STANDARD_OUT
    then2

MyClassTests STANDARD_OUT
    afterSpec
a
cool, then it's clear the issue is the kotest intellij plugin in Android Studio (at least for now)
assuming you do use the kotest plugin for Android Studio (if that's even a thing)
l
Confirm, I just opened the same project in IntelliJ, and there running it with the gutter icon produces correct order of
println()
outputs
Copy code
beforeSpec
context1
given1
and1
when1
then1
when2
then2
afterSpec
a
now if you can just confirm whether you use this plugin in both IntelliJ and Android Studio I should be able ti have a full picture 🙂 https://kotest.io/docs/intellij/intellij-plugin.html
l
Android Studio:
In IntelliJ I have the same version
👍 1
a
perfect, I will check this whenever possible, although I'd have to investigate the plugin and android studio (which I rarely use) and might take me time 🙂 - thanks for giving all the context
l
You're welcome. Glad I could help!