Track it down

Report a typo

This is a little puzzle to test your understanding of the order in which test class methods execute.

Take a look at this test class:

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
internal class BetaTest {

    var number = 0

    init {
        number = 10
    }

    @BeforeAll
    fun method3() {
        number += 11
    }

    @AfterAll
    fun method4() {
        number /= 3
    }

    @BeforeEach
    fun method2() {
        number -= 4
    }

    @AfterEach
    fun method5() {
        println(number)
    }

    @Test
    fun method6() {
        number += 9
    }
}

What number will be printed if we run this test?

Enter a number
___

Create a free account to access the full topic