티스토리 뷰

보통 단위 테스트는 빠르게 실행되며 불편하지 않습니다. 
하지만 프로젝트가 커지면 통합테스트가 많은 시간을 잡아먹는 경우가 있습니다.
그래서 통합테스트와 단위테스트를 분리하는 것이 좋습니다.

기본 Java 프로젝트 구조

프로젝트 구조

build.gradle

plugins {
    id 'org.springframework.boot' version '2.2.2.RELEASE'
    id 'io.spring.dependency-management' version '1.0.8.RELEASE'
    id 'java'
}

group = 'gradle'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}

통합테스트를 위한 디렉토리 추가

integration 디렉토리를 생성했지만, IDE가 해당 디렉토리를 테스트 소스 디렉토리로 인식하지 못하고 있습니다.

build.gradle 에 추가해봅시다.

sourceSets {
    integration {
        java.srcDir "$projectDir/src/integration/java"
        resources.srcDir "$projectDir/src/integration/resources"
        compileClasspath += main.output + test.output
        runtimeClasspath += main.output + test.output
    }
}

이렇게 하면 통합테스트 디렉토리가 활성화 됩니다.

(주의)

그리고 통합테스트틀 위한 dependencies를 추가하기 위해서는 integrationImplementation을 사용해야합니다.

 

마지막으로 task를 정의합니다.

task integrationTest(type: Test) {
    testClassesDirs = sourceSets.integration.output.classesDirs
    classpath = sourceSets.integration.runtimeClasspath
}

check.dependsOn integrationTest

 

이렇게 작성하면 체크작업을 할 때 integrationTest가 작동하도록 합니다.

 

코드가 궁금하다면...
https://github.com/hyperpace/study_gradle
 

hyperpace/study_gradle

Contribute to hyperpace/study_gradle development by creating an account on GitHub.

github.com

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/07   »
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 31
글 보관함