hello. I am facing a "possibly" simple issue. How ...
# kotest
m
hello. I am facing a "possibly" simple issue. How would i initialise the class under test before each test run in a ShouldSpec test? I have a test like the one below but i do not know how to correctly initialize the
engine
. I don't want to change the isolation mode as i would like to do some other data loading once upfront (to feed the engine).
Copy code
class EngineTest : ShouldSpec({

    val engineInput = loadExpensiveInput()

    // does not work and lateinit is not available
    var engine: Engine
    
    beforeEach {
        engine = Engine(engineInput)
    }

    should("be ready") {
        engine.ready shouldBe true
    }
}
solved 1
d
This way is how it is usually done if you want to have a new engine for each test
m
@Davio Which way would that be?
d
Well, what is your goal? If your goals is to initialize the engine for each test, then putting it inside beforeEach is usually how it's done
m
where would i store the variable to reference in a test?
i don't want to make it nullable
d
You can use lateinit here for Engine
m
unfortunately not because lateinit is only available for class properties not for regular vars (as is the case in the block here).
d
Eeuhm, it works in my code?
m
Ok, you are right. it was an error on my side 🫣
This specifies that it does also work for local variables
m
indeed. thanks for bringing that up again 👍