Skip to content

Commit

Permalink
✨feature : 테스트툴 연동
Browse files Browse the repository at this point in the history
 - kotest 연동
 - cucumber 연동
  • Loading branch information
ParkYunHo committed Jun 26, 2023
1 parent 689c220 commit ac2800f
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 17 deletions.
13 changes: 10 additions & 3 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ plugins {
dependencies {
implementation(project(":core"))

// implementation("org.springframework.boot:spring-boot-starter-web")

implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.boot:spring-boot-starter-aop")

implementation("org.springframework.cloud:spring-cloud-starter-openfeign:4.0.3")

implementation("jakarta.servlet:jakarta.servlet-api:6.0.0")

// Cucumber
testImplementation("io.cucumber:cucumber-java:7.12.1")
testImplementation("io.cucumber:cucumber-spring:7.12.1")
testImplementation("io.cucumber:cucumber-junit-platform-engine:7.12.1")
testImplementation("org.junit.platform:junit-platform-suite-api")

testImplementation("io.projectreactor:reactor-test")
}
13 changes: 0 additions & 13 deletions api/src/test/kotlin/com/john/api/ApiApplicationTests.kt

This file was deleted.

11 changes: 11 additions & 0 deletions api/src/test/kotlin/com/john/lotto/ApiApplicationTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.john.lotto

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@SpringBootApplication
class ApiApplicationTests {
fun main(args: Array<String>) {
runApplication<ApiApplicationTests>(*args)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.john.lotto.cucumber.feature

import io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME
import io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME
import org.junit.platform.suite.api.ConfigurationParameter
import org.junit.platform.suite.api.IncludeEngines
import org.junit.platform.suite.api.SelectClasspathResource
import org.junit.platform.suite.api.Suite

/**
* @author yoonho
* @since 2023.06.23
*/
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("cucumber/feature")
@ConfigurationParameter(
key = GLUE_PROPERTY_NAME,
value = "cucumber.feature"
)
@ConfigurationParameter(
key = PLUGIN_PROPERTY_NAME,
value = "pretty"
)
class RunCucumberTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.john.lotto.cucumber.feature

import com.john.lotto.ApiApplicationTests
import io.cucumber.spring.CucumberContextConfiguration
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ActiveProfiles

/**
* @author yoonho
* @since 2023.06.23
*/
@SpringBootTest(classes = [ApiApplicationTests::class])
@CucumberContextConfiguration
@AutoConfigureMockMvc
@AutoConfigureWebTestClient
@ActiveProfiles("api-test")
class SpringIntegrationTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.john.lotto.cucumber.feature.step.number

import com.john.lotto.common.handler.WebFluxExceptionHandler
import com.john.lotto.number.adapter.`in`.web.NumberRouter
import io.cucumber.java.Before
import io.cucumber.java.ko.그러면
import io.cucumber.java.ko.만약
import io.cucumber.java.ko.먼저
import io.kotest.assertions.print.print
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpMethod
import org.springframework.http.MediaType
import org.springframework.test.web.reactive.server.WebTestClient
import org.springframework.web.reactive.function.server.HandlerStrategies
import org.springframework.web.util.UriComponentsBuilder

/**
* @author yoonho
* @since 2023.06.23
*/
class NumberStep {
private val log = LoggerFactory.getLogger(this::class.java)

@Autowired
private lateinit var router: NumberRouter

private lateinit var webTestClient: WebTestClient
private lateinit var result: WebTestClient.ResponseSpec

private var drwtNo: Int = 0

@Before(value = "@number")
fun init() {
webTestClient = WebTestClient.bindToRouterFunction(router.numberRouterFunction())
.handlerStrategies(
HandlerStrategies.builder()
.exceptionHandler(WebFluxExceptionHandler())
.build()
)
.build()
}

@먼저("로또번호조회API 호출을 위한 {int} 있다")
fun 로또번호조회API_호출을_위한_있다(drwtNo: Int) {
this.drwtNo = drwtNo
}

@만약("로또번호조회API {string} 요청하면")
fun 로또번호조회API_요청하면(url: String) {
val uriComponents = UriComponentsBuilder
.fromUriString(url)
.queryParam("drwtNo", drwtNo)
.build(false)

result = webTestClient
.method(HttpMethod.GET)
.uri(uriComponents.toUriString())
.contentType(MediaType.APPLICATION_JSON)
.exchange()
}

@그러면("로또번호조회API 호출결과 {int} 확인한다")
fun 로또번호조회API_호출결과_확인한다(statusCode: Int) {
result
.expectStatus().isEqualTo(statusCode)
.print()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.john.lotto.number.application

import com.john.lotto.ApiApplicationTests
import io.kotest.core.spec.style.BehaviorSpec
import io.kotest.matchers.shouldNotBe
import org.junit.jupiter.api.Assertions.*
import org.slf4j.LoggerFactory
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ActiveProfiles

@SpringBootTest(classes = [ApiApplicationTests::class])
@ActiveProfiles("api-test")
class NumberServiceTest(
private val numberService: NumberService
): BehaviorSpec({
val log = LoggerFactory.getLogger(this::class.java)

Given("먼저, 특정 로또번호 조회를 위한 파라미터가 세팅되어 있다.") {
val drwtNo = 1072L

When("만약, 특정 로또번호 조회를 요청하면") {
val result = numberService.findLottoNumber(drwtNo = drwtNo).block()

Then("그러면, 특정 로또번호 조회 결과를 확인한다.") {
log.info(" >>> [findLottoNumber] result: $result")
result shouldNotBe null
}
}
}
})
28 changes: 28 additions & 0 deletions api/src/test/resources/application-api-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
spring:
config:
activate:
on-profile: api-test
jpa:
show-sql: true
hibernate:
ddl-auto: create-drop
generate-ddl: true
datasource:
hikari:
connection-timeout: 5000
minimum-idle: 10
maximum-pool-size: 100

hibernate:
show_sql: false
format_sql: false
physical_naming_strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

vault:
uri: http://localhost:8200
token: admin
app-role:
role-id:
secret-id:
secret:
appconfig: oauth2-app/local
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# language: ko
기능: 로또번호 조회 API 통합테스트
모든 사용자는 로또번호 조회 API를 호출할 수 있다.

@number
시나리오 개요: 로또번호조회 API를 호출한다.
먼저 로또번호조회API 호출을 위한 <drwtNo> 있다
만약 로또번호조회API "<url>" 요청하면
그러면 로또번호조회API 호출결과 <statusCode> 확인한다

:
| drwtNo | url | statusCode |
| 1072 | /api/number | 200 |
| 9999 | /api/number | 400 |
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.john.lotto.number

import com.john.lotto.CoreApplicationTests
import io.kotest.core.spec.style.BehaviorSpec
import io.kotest.matchers.shouldNotBe
import org.junit.jupiter.api.Assertions.*
Expand All @@ -13,7 +14,7 @@ import javax.sql.DataSource
* @author yoonho
* @since 2023.06.22
*/
@SpringBootTest("CoreApplicationTests")
@SpringBootTest(classes = [CoreApplicationTests::class])
@ActiveProfiles("core-test")
class NumberRepositoryTest(
private val numberRepository: NumberRepository,
Expand Down

0 comments on commit ac2800f

Please sign in to comment.