Klitos Kyriacou
07/26/2023, 3:49 PMbeforeTest
, beforeEach
and beforeAny
? I've read the documentation but I'm still confused.LeoColman
07/26/2023, 4:49 PMKlitos Kyriacou
07/26/2023, 4:52 PMbeforeTest
has the same usage as beforeAny
and is invoked at the start of both a container and a test, whereas beforeEach
is invoked only before a test. To illustrate:
class MyTest : FreeSpec({
"container1" - {
"test1" {
println("test1")
}
}
beforeAny { println("beforeAny $it") }
beforeEach { println("beforeEach $it") }
})
In the above, the beforeAny
(or beforeTest
) is invoked twice: once for the container and once again for the test. On the other hand, beforeEach
is invoked only once, for the test.