티스토리 뷰
보통 단위 테스트는 빠르게 실행되며 불편하지 않습니다.
하지만 프로젝트가 커지면 통합테스트가 많은 시간을 잡아먹는 경우가 있습니다.
그래서 통합테스트와 단위테스트를 분리하는 것이 좋습니다.
기본 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가 작동하도록 합니다.
'개발 > 기술' 카테고리의 다른 글
[네트워크] SSL/TLS (0) | 2019.12.21 |
---|---|
[OAuth] 정리 (0) | 2019.12.10 |