반응형
Single Instance
- 디폴트 isolation mode
- spec class는 한 번만 생성되고, 각 테스트를 실행.
class MyTests : WordSpec({
val id = UUID.randomUUID()
"a" should {
println(id)
"b" {
println(id)
}
"c" {
println(id)
}
}
})
e37fb8c6-6fbb-4e33-98f7-acf3c8d439bf
e37fb8c6-6fbb-4e33-98f7-acf3c8d439bf
e37fb8c6-6fbb-4e33-98f7-acf3c8d439bf
InstancePerTest
- 각 테스트 실행시마다 spec class를 생성
import io.kotest.core.spec.IsolationMode
import io.kotest.core.spec.style.WordSpec
import java.util.concurrent.atomic.AtomicInteger
class MyTests : WordSpec() {
override fun isolationMode(): IsolationMode = IsolationMode.InstancePerTest
private val counter = AtomicInteger(0)
init {
"a" should {
println("a=" + counter.getAndIncrement())
"b" {
println("b=" + counter.getAndIncrement())
}
"c" {
println("c=" + counter.getAndIncrement())
}
}
}
}
a=0
a=0
b=1
a=0
c=1
InstancePerLeaf
- InstancePerTest와 동일
- InstancePerTest는 context 내부까지 실행한다면, InstancePerLeaf는 context 내부는 실행하지 않음
import io.kotest.core.spec.IsolationMode
import io.kotest.core.spec.style.WordSpec
import java.util.concurrent.atomic.AtomicInteger
class MyTests : WordSpec() {
override fun isolationMode(): IsolationMode = IsolationMode.InstancePerLeaf
private val counter = AtomicInteger(0)
init {
"a" should {
println("a=" + counter.getAndIncrement())
"b" {
println("b=" + counter.getAndIncrement())
}
"c" {
println("c=" + counter.getAndIncrement())
}
}
}
}
a=0
b=1
a=0
c=1
반응형
'Development > Kotest' 카테고리의 다른 글
[Kotest] extensions (0) | 2023.11.04 |
---|---|
[Kotest] lifecycle hook (0) | 2023.11.04 |
[Kotest] conditional evaluation (0) | 2023.11.04 |
[Kotest] testing styles (0) | 2023.11.04 |
[Kotest] 기본 (0) | 2023.11.04 |