통합 테스트를 구성하는 과정에 내용을 main 외에 별도의 디렉토리에 구성하는 사항을 해결하고자 합니다.
maven에서는 org.codehaus.mojo:build-helper-maven-plugin 를 적용해서 POM에 디렉토리를 적용할 수 있습니다.
- source dir
- resource dir
- test source dir
- test resource dir
적용법은 아래와 같습니다.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-integration-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/integrationTest/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-integration-test-resource</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/integrationTest/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Gradle에서는 sourceSets 을 통해 간단하게 해결할 수 있습니다.
plugins {
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
sourceSets {
test {
java {
srcDirs 'src/integrationTest/java'
}
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.projectlombok:lombok:1.18.20'
runtimeOnly 'com.h2database:h2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.cucumber:cucumber-java8:7.8.1'
testImplementation 'io.cucumber:cucumber-spring:7.8.1'
}
tasks.named('test') {
useJUnitPlatform()
}
'Backend > SpringBoot' 카테고리의 다른 글
[SpringBoot] JUnit Test Class AssertJ기본 설정하기 (0) | 2023.06.26 |
---|---|
[SpringBoot]JUnit5 Mock기반 테스트 (0) | 2023.01.31 |
[Mybatis] All Elements are null (0) | 2022.10.24 |
[Spring Boot]Response Handling 하기-Flux (0) | 2022.07.10 |
[Spring Boot]Response Handling 하기-MVC (0) | 2022.07.09 |