-
Notifications
You must be signed in to change notification settings - Fork 40
[semi.colon] Step2 미션 제출합니다. #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: un-known0
Are you sure you want to change the base?
Changes from all commits
486d8c6
6ea2b90
d236e1d
945ed3f
be538ce
5285ced
6693a80
f38c2bf
e14846e
07c0e2c
a507acc
07e0f44
43dcca9
d0c3668
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| .gradle | ||
| build | ||
| .idea | ||
| *.iml | ||
| .git | ||
| .gitignore | ||
| .DS_Store | ||
| docs | ||
| *.md |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| FROM eclipse-temurin:21-jdk AS builder | ||
| WORKDIR /app | ||
| COPY . . | ||
| RUN ./gradlew bootJar --no-daemon | ||
|
|
||
| FROM eclipse-temurin:21-jre-alpine | ||
| RUN apk add --no-cache curl | ||
| WORKDIR /app | ||
| COPY --from=builder /app/build/libs/*.jar app.jar | ||
| ENTRYPOINT ["java", "-jar", "app.jar"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,24 @@ | ||
| # spring-gift-test | ||
| # spring-gift-test | ||
|
|
||
| ## 사전 요구사항 | ||
|
|
||
| - Java 21 | ||
| - Docker (Cucumber 테스트 실행 시 필요) | ||
|
|
||
| ## 테스트 실행 방법 | ||
|
|
||
| ### 기존 인수 테스트 (H2) | ||
| ```bash | ||
| ./gradlew test | ||
| ``` | ||
| RestAssured 인수 테스트 3개를 H2 인메모리 DB로 실행합니다. | ||
|
|
||
| ### Cucumber 테스트 (Docker 환경) | ||
| ```bash | ||
| ./gradlew cucumberTest | ||
| ``` | ||
| Docker Compose로 PostgreSQL + 애플리케이션 컨테이너를 자동 시작하고, Cucumber 시나리오 8개를 실행한 후 컨테이너를 자동 종료합니다. | ||
|
|
||
| ### Cucumber 시나리오 구조 | ||
| - 시나리오 정의: `src/test/resources/features/*.feature` | ||
| - Step 구현: `src/test/java/gift/acceptance/cucumber/` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,10 +22,43 @@ dependencies { | |
| implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' | ||
| implementation 'org.springframework.boot:spring-boot-starter-web' | ||
| runtimeOnly 'com.h2database:h2' | ||
| runtimeOnly 'org.postgresql:postgresql' | ||
| testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
| testImplementation 'io.rest-assured:rest-assured' | ||
| testImplementation platform('io.cucumber:cucumber-bom:7.22.0') | ||
| testImplementation 'io.cucumber:cucumber-java' | ||
| testImplementation 'io.cucumber:cucumber-spring' | ||
| testImplementation 'io.cucumber:cucumber-junit-platform-engine' | ||
| testImplementation 'org.junit.platform:junit-platform-suite' | ||
| } | ||
|
|
||
| tasks.named('test') { | ||
| useJUnitPlatform() | ||
| useJUnitPlatform { | ||
| excludeEngines 'cucumber' | ||
| } | ||
| exclude '**/CucumberSuite*' | ||
| } | ||
|
|
||
| tasks.register('dockerBuild', Exec) { | ||
| commandLine 'docker-compose', 'build' | ||
| } | ||
|
|
||
| tasks.register('dockerUp', Exec) { | ||
| dependsOn 'dockerBuild' | ||
| commandLine 'docker-compose', 'up', '-d', '--wait' | ||
| } | ||
|
|
||
| tasks.register('dockerDown', Exec) { | ||
| commandLine 'docker-compose', 'down', '-v' | ||
| } | ||
|
|
||
| tasks.register('cucumberTest', Test) { | ||
| useJUnitPlatform { | ||
| includeEngines 'cucumber' | ||
| } | ||
| systemProperty 'cucumber.glue', 'gift.acceptance.cucumber' | ||
| systemProperty 'cucumber.features', 'classpath:features' | ||
| systemProperty 'cucumber.plugin', 'pretty' | ||
| dependsOn 'dockerUp' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 명령어 하나만 실행해도 모두 동작할 수 있도록 잘 구성해주셨네요 👍 |
||
| finalizedBy 'dockerDown' | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 한번에 전체 스택을 관리하기보다는 infra영역과 어플리케이션 영역을 분리해볼수도 있을 것 같네요. msa 환경이나 여러 infra 환경이 있다라는 것을 가정한다면, 이후에 docker-compose.yml을 관리하기 힘들어질 수 있고 각 목적에 따라 분리했을때의 장점도 고민 포인트가 될 수 있을 것 같아요. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| services: | ||
| postgres: | ||
| image: postgres:17-alpine | ||
| environment: | ||
| POSTGRES_DB: gift_test | ||
| POSTGRES_USER: test | ||
| POSTGRES_PASSWORD: test | ||
| ports: | ||
| - "5432:5432" | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U test -d gift_test"] | ||
| interval: 3s | ||
| timeout: 3s | ||
| retries: 5 | ||
|
|
||
| app: | ||
| build: . | ||
| ports: | ||
| - "28080:8080" | ||
| depends_on: | ||
| postgres: | ||
| condition: service_healthy | ||
| environment: | ||
| SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/gift_test | ||
| SPRING_DATASOURCE_USERNAME: test | ||
| SPRING_DATASOURCE_PASSWORD: test | ||
| SPRING_JPA_HIBERNATE_DDL_AUTO: create | ||
| SPRING_JPA_DATABASE_PLATFORM: org.hibernate.dialect.PostgreSQLDialect | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "curl -f http://localhost:8080/api/categories || exit 1"] | ||
| interval: 5s | ||
| timeout: 3s | ||
| retries: 10 | ||
| start_period: 30s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테스트까지 컨테이너에 넣는 방식의 장점에 대해서 고민해보면 좋을 것 같아요. 현재는 별도로 호출해도 되는 환경이지만 다른 사람의 환경, ci의 환경 모두 다른 환경에서 테스트 호출이 실패하는 경우를 가정한다면 가능하면 모두 docker 컨테이너 안에서 실행이 될 수 있도록 구성하는 것도 좋을 것 같네요 :)