Skip to content

Commit

Permalink
[HOME] 통합 테스트 코드 추가 (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkyoungdeok authored Feb 25, 2024
1 parent 79d4975 commit cf0c140
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 41 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ jobs:
- name: Grant Execute Permission For Gradlew
run: chmod +x gradlew
- name: Test With Gradle
run: ./gradlew test jacocoTestReport
- name: Add coverage to PR
uses: madrapps/[email protected]
run: ./gradlew test koverXmlReport
- name: Add coverage report to PR
id: kover
uses: mi-kas/kover-report@v1
with:
paths: server/build/reports/jacoco/test/jacocoTestReport.xml
path: ${{ github.workspace }}/build/reports/kover/report.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 70
min-coverage-changed-files: 70
title: Code Coverage
update-comment: true
title: "Coverage Report"
min-coverage-overall: 10
min-coverage-changed-files: 10
coverage-counter-type: LINE
40 changes: 8 additions & 32 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import org.jlleitschuh.gradle.ktlint.KtlintExtension
import org.springframework.boot.gradle.tasks.bundling.BootJar

plugins {
id("jacoco")
id("org.springframework.boot") version "2.7.5"
id("io.spring.dependency-management") version "1.0.15.RELEASE"
id("org.jlleitschuh.gradle.ktlint") version "11.3.1"
id("io.gitlab.arturbosch.detekt") version "1.21.0"
id("org.jetbrains.dokka") version "1.7.20"
id("org.jetbrains.kotlinx.kover") version "0.7.3"

id("com.google.protobuf") version "0.8.15"

Expand All @@ -20,10 +20,6 @@ plugins {
kotlin("plugin.noarg") version "1.7.0"
}

jacoco {
toolVersion = "0.8.8"
}

group = "com.fone.filmone"
version = "0.0.1-SNAPSHOT"

Expand Down Expand Up @@ -69,8 +65,8 @@ subprojects {
plugin("org.springframework.boot")
plugin("io.spring.dependency-management")
plugin("org.jetbrains.dokka")
plugin("jacoco")
plugin("io.gitlab.arturbosch.detekt")
plugin("org.jetbrains.kotlinx.kover")
}

java.sourceCompatibility = JavaVersion.VERSION_17
Expand All @@ -93,32 +89,6 @@ subprojects {
withType<Test> {
useJUnitPlatform()
systemProperty("file.encoding", "UTF-8")

// 테스트 실행 이후에 항상 JaCoCo 리포트를 생성합니다.
finalizedBy(jacocoTestReport)
}

jacocoTestReport {
reports {
xml.required.set(true)
csv.required.set(true)
html.required.set(true)
}
finalizedBy(jacocoTestCoverageVerification)
}

jacocoTestCoverageVerification {
violationRules {
rule {
enabled = true
element = "CLASS"
limit {
counter = "LINE"
value = "COVEREDRATIO"
minimum = "0".toBigDecimal()
}
}
}
}
}

Expand All @@ -140,3 +110,9 @@ subprojects {
tasks.dokkaHtmlMultiModule.configure {
outputDirectory.set(buildDir.resolve("$rootDir/devdocs"))
}

dependencies {
subprojects.forEach {
kover(it)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class HomeController {
@RequestHeader(value = "Authorization", required = false) token: String,
): CommonResponse<HomeDto> {
val client: HttpClient = HttpClient.create().responseTimeout(Duration.ofSeconds(1))

val webClient: WebClient = WebClient.builder().clientConnector(ReactorClientHttpConnector(client))
.baseUrl("http://localhost:$serverPort").build()

Expand Down
2 changes: 1 addition & 1 deletion server/src/test/kotlin/com/fone/common/IntegrationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ContextConfiguration
import org.testcontainers.junit.jupiter.Testcontainers

@SpringBootTest(classes = [ServerApplication::class])
@SpringBootTest(classes = [ServerApplication::class], webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@Testcontainers
@AutoConfigureWebTestClient
@ContextConfiguration(initializers = [IntegrationTestContextInitializer::class])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.fone.home.presentation

import com.fone.common.CommonUserCallApi
import com.fone.common.CustomDescribeSpec
import com.fone.common.IntegrationTest
import com.fone.common.doGet
import org.springframework.test.web.reactive.server.WebTestClient

@IntegrationTest
class HomeControllerTest(client: WebTestClient) : CustomDescribeSpec() {

private val retrieveUrl = "/api/v1/homes"

init {
val (accessToken, _) = CommonUserCallApi.getAccessToken(client)

describe("#retrieveHome") {
context("when retrieve home") {
it("should return home info") {
client.doGet(retrieveUrl, accessToken).expectStatus().isOk.expectBody()
.consumeWith { println(it) }
.jsonPath("$.result")
.isEqualTo("SUCCESS")
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class JobOpeningRepositoryImplTest(
it("성공한다") {
val jobOpenings = jobOpeningRepository.findByFilters(
org.springframework.data.domain.Pageable.unpaged(),
RetrieveJobOpeningsRequest(type = Type.ACTOR)
RetrieveJobOpeningsRequest(type = Type.STAFF)
)

jobOpenings.size shouldBe 0
Expand Down

0 comments on commit cf0c140

Please sign in to comment.