Notice
Recent Posts
Recent Comments
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Archives
Today
Total
관리 메뉴

Keep calm and code on

gradle kotlin + intelliJ 환경 integrationTest 테스트폴더로 인식시키기 본문

카테고리 없음

gradle kotlin + intelliJ 환경 integrationTest 테스트폴더로 인식시키기

Sejong Park 2021. 12. 5. 20:51

 

현재 프로젝트에서는 integrationTest와 별도의 test폴더를 분리하여 사용하고 있다. 아래와 같이 설정하여 integrationTest폴더를 별도로 설정하고 컴파일/테스트를 분리하여 처리하고 있다.

 

plugins {
    kotlin("jvm") version "1.6.0"
}

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

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
}

sourceSets {
    create("integrationTest") {
        compileClasspath += sourceSets.main.get().output + sourceSets.test.get().output
        runtimeClasspath += sourceSets.main.get().output + sourceSets.test.get().output

        resources.srcDir(file("src/integrationTest/resources"))
    }
}

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

task<Test>("integrationTest") {
    description = "Runs integration tests."
    group = "verification"

    testClassesDirs = sourceSets["integrationTest"].output.classesDirs
    classpath = sourceSets["integrationTest"].runtimeClasspath

    shouldRunAfter("test")
}

val integrationTestImplementation: Configuration by configurations.getting {
    extendsFrom(configurations.implementation.get(), configurations.testImplementation.get())
}

tasks.withType<Test> {
    useJUnitPlatform()
}

위과같이 설정할 경우 gradle을 바탕으로 integrationTest에 관련된 태스크나 빌드는 무리없이 수행이 된다.

 

하지만 intelliJ에서는 integrationTest 폴더를 일반 source 폴더로 인식한다. 그렇기에 특정 클래스에서 테스트클래스로 빠른이동을 하는 기능등이 제대로 동작하지 않거나, 파일이동시 패키지가 함께 변경되지 않는 등의 자잘한 불편함이 괴롭히는 상황이 반복되었다.

 

intelliJ는 gradle과 통합된 환경을 제공한다. gradle의 설정에 맞추어 테스트소스폴더와 소스폴더등을 분리해서 제공하는 등의 다양한 기능을 gradle의 설정을 기반으로 세팅된다. intelliJ에서 integrationTest 폴더가 테스트소스로 인식하기 위해서는 gradle에서 별도 설정이 필요하다.

 

gradle에서는 "idea"  플러그인을 이용해 문제를 해결할 수 있다. 아래와 같이 gradle plugin에 "idea"의존관계와 해당 설정을 변경해보자.

 

plugins {
    // ...
    idea
}

// ...
// ...


idea.module {
    testSourceDirs = testSourceDirs + project.sourceSets.getByName("integrationTest").allSource.srcDirs
    testResourceDirs = testResourceDirs + project.sourceSets.getByName("integrationTest").resources.srcDirs
}

이전과는 다르게 테스트폴더로 정상 인식되는걸 확인할 수 있다.

Comments