Spring/Kotlin

[Kotlin + Springboot + Kotest] Kotest 알아보자.

For_HW 2021. 8. 1. 20:09

코틀린으로 서버사이드로 개발을 하던 도중, kotest 라는 테스트 툴에  대해서 알게되었다.

한번 사용해보자!


Kotest 준비

 Maven dependency 추가해주기.

<!--  kotest dependency 추가-->
        <dependency>
            <groupId>io.kotest</groupId>
            <artifactId>kotest-runner-junit5-jvm</artifactId>
            <version>4.6.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.kotest</groupId>
            <artifactId>kotest-assertions-core-jvm</artifactId>
            <version>4.6.1</version>
            <scope>runtime</scope>
        </dependency>

gradle dependency 추가해주기.

//kotest 추가.
    runtimeOnly("io.kotest:kotest-assertions-core-jvm:4.6.1")
    testImplementation("io.kotest:kotest-runner-junit5-jvm:4.6.1")

 

Intellij 에서도 플러그인 설치를 해줘야 함!


Kotest  사용해보기!

 

우선 Kotest 는 10가지 테스트 레이아웃을 제공한다.

(기존 테스트 프레임워크에 영향을 받은 레이아웃과, Kotest만의 테스트 레이아웃을 제공하고있다.)

 

Kotest 10가지 테스트 레이아웃

전후처리

기존에 @ BeforeEach, @BeforeAll, @AfterEach 등 과 같은 어노테이션으로 사용하지 않고,

각 Spec의 SpecFunctionCallbacks 인터페이스에 의해 override를 통하여 구현 할 수 있다.

 

interface SpecFunctionCallbacks {
   fun beforeSpec(spec: Spec) {}
   fun afterSpec(spec: Spec) {}
   fun beforeTest(testCase: TestCase) {}
   fun afterTest(testCase: TestCase, result: TestResult) {}
   fun beforeContainer(testCase: TestCase) {}
   fun afterContainer(testCase: TestCase, result: TestResult) {}
   fun beforeEach(testCase: TestCase) {}
   fun afterEach(testCase: TestCase, result: TestResult) {}
   fun beforeAny(testCase: TestCase) {}
   fun afterAny(testCase: TestCase, result: TestResult) {}
}

 

실제로 사용해보자.


참고한 글

https://github.com/kotest/kotest

 

GitHub - kotest/kotest: Powerful, elegant and flexible test framework for Kotlin with additional assertions, property testing an

Powerful, elegant and flexible test framework for Kotlin with additional assertions, property testing and data driven testing - GitHub - kotest/kotest: Powerful, elegant and flexible test framework...

github.com

https://kotest.io/

 

Kotest | Kotest

Flexible, powerful and elegant kotlin test framework with multiplatform support

kotest.io

https://isntyet.github.io/kotlin/Kotest-%ED%95%B4%EB%B3%B4%EA%B8%B0/

 

Kotest 해보기

Kotest

isntyet.github.io

 

'Spring/Kotlin'의 다른글

  • 현재글 [Kotlin + Springboot + Kotest] Kotest 알아보자.

관련글