execution-order-in-DescribeSpec

z

Recorded output of command:

    [INFO][elapsed:    9ms][2️⃣][①][coroutname:@coroutine#3]   [1]: Describe-Level-1
    [INFO][elapsed:   30ms][2️⃣][①][coroutname:@coroutine#3]     [2]: BeforeEach IN Describe-Level-1
    [INFO][elapsed:   32ms][2️⃣][①][coroutname:@coroutine#3]     [3]: IT-1 in Describe-Level-1
    [INFO][elapsed:   33ms][2️⃣][①][coroutname:@coroutine#3]
    [INFO][elapsed:   39ms][2️⃣][①][coroutname:@coroutine#3]     [4]: Describe-Level-2
    [INFO][elapsed:   41ms][2️⃣][①][coroutname:@coroutine#3]       [5]: BeforeEach IN Describe-Level-1
    [INFO][elapsed:   41ms][2️⃣][①][coroutname:@coroutine#3]       [6]: BeforeEach IN Describe-Level-2
    [INFO][elapsed:   41ms][2️⃣][①][coroutname:@coroutine#3]       [7]: IT-1 in Describe-Level-2
    [INFO][elapsed:   41ms][2️⃣][①][coroutname:@coroutine#3]
    [INFO][elapsed:   43ms][2️⃣][①][coroutname:@coroutine#3]       [8]: BeforeEach IN Describe-Level-1
    [INFO][elapsed:   43ms][2️⃣][①][coroutname:@coroutine#3]       [9]: BeforeEach IN Describe-Level-2
    [INFO][elapsed:   43ms][2️⃣][①][coroutname:@coroutine#3]       [10]: IT-2 in Describe-Level-2
    [INFO][elapsed:   44ms][2️⃣][①][coroutname:@coroutine#3]
    [INFO][elapsed:   45ms][2️⃣][①][coroutname:@coroutine#3]     [11]: BeforeEach IN Describe-Level-1
    [INFO][elapsed:   46ms][2️⃣][①][coroutname:@coroutine#3]     [12]: IT-2 in Describe-Level-1
    [INFO][elapsed:   46ms][2️⃣][①][coroutname:@coroutine#3]

Code

package com.glassthought.sandbox

import com.glassthought.sandbox.impl.CustomDescribeSpec
import com.glassthought.sandbox.impl.out

class KotestExecutionOrderTest : CustomDescribeSpec({

  describe("Describe-Level-1") {
    incrementCountAndPrint("Describe-Level-1")

    beforeEach {
      incrementCountAndPrint("BeforeEach IN Describe-Level-1")
    }

    it("IT-1 in Describe-Level-1") {
      incrementAndPrintForIt("IT-1 in Describe-Level-1")
    }

    describe("Describe-Level-2") {
      beforeEach {
        incrementCountAndPrint("BeforeEach IN Describe-Level-2")
      }

      incrementCountAndPrint("Describe-Level-2")

      it("IT-1 in Describe-Level-2") {
        incrementAndPrintForIt("IT-1 in Describe-Level-2")
      }

      it("IT-2 in Describe-Level-2") {
        incrementAndPrintForIt("IT-2 in Describe-Level-2")
      }
    }

    it("IT-2 in Describe-Level-1") {
      incrementAndPrintForIt("IT-2 in Describe-Level-1")
    }
  }
})


private var count = 0
private suspend fun incrementCountAndPrint(string: String) {
  count += 1

  out.info("[${count}]: ${string}")
}

private suspend fun incrementAndPrintForIt(msg: String) {
  incrementCountAndPrint(msg)
  out.info("")
}

Command to reproduce:

gt.sandbox.checkout.commit 9ad8f194aba389b94ce8 \
&& cd "${GT_SANDBOX_REPO}" \
&& cmd.run.announce "./gradlew test --rerun-tasks"

Backlinks