코틀린으로 서버사이드로 개발을 하던 도중, 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만의 테스트 레이아웃을 제공하고있다.)
전후처리
기존에 @ 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
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+JPA] Exception Handling by Kotlin (0) | 2021.08.31 |
---|---|
[SpringBoot + Kotlin + JPA] 간단한 게시글 CRUD REST Api 구현. (0) | 2021.08.08 |
[Springboot + Kotlin] Slack 채널 메세지 전송 연동. (0) | 2021.08.06 |
[Kotlin + Springboot + JPA] Entity 생성에 관하여. (0) | 2021.07.28 |
[Kotlin + SpringBoot + JPA] Swagger 설정 및 동작 (0) | 2021.07.18 |