강좌/Kotlin

build.gradle.kts Kotlin JUnit5 AssertJ

여름나라겨울이야기 2019. 9. 17. 17:38
728x90

dependencies 추가

JUnit5

testImplementation("org.junit.jupiter:junit-jupiter:5.5.2")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5:1.3.50")

AssertJ

testImplementation("org.assertj:assertj-core:3.13.2")

Test 를 위한 Task 추가

tasks.withType<Test> {
    useJUnitPlatform()
}

junit4, hamcrest 의존성 제거

testImplementation("org.springframework.boot:spring-boot-starter-test") {
  exclude(module = "junit")
  exclude(module = "hamcrest-core")
  exclude(module = "hamcrest-library")
}

 

전체 코드

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("org.springframework.boot") version "2.1.8.RELEASE"
    id("io.spring.dependency-management") version "1.0.8.RELEASE"
    kotlin("jvm") version "1.2.71"
    kotlin("plugin.spring") version "1.2.71"
}

group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-webflux")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    // junit4, hamcrest 의존성 제거
    testImplementation("org.springframework.boot:spring-boot-starter-test") {
        exclude(module = "junit")
        exclude(module = "hamcrest-core")
        exclude(module = "hamcrest-library")
    }
    testImplementation("io.projectreactor:reactor-test")

    // JUnit5
    testImplementation("org.junit.jupiter:junit-jupiter:5.5.2")
    testImplementation("org.jetbrains.kotlin:kotlin-test-junit5:1.3.50")
    // AssertJ
    testImplementation("org.assertj:assertj-core:3.13.2")
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "1.8"
    }
}

// JUnit5
tasks.withType<Test> {
    useJUnitPlatform()
}
반응형