-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from co-co-gong/feat#21
test: JaCoCo & Codecov
- Loading branch information
Showing
10 changed files
with
399 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: "CI/CD" | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: test | ||
run: | | ||
echo "test" | ||
# TODO: ghcr.io & Argo CD (related: #22) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: "Spring Test" | ||
|
||
on: | ||
push: | ||
branches: | ||
- "*" | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
permissions: | ||
contents: write | ||
actions: read | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-java@v4 | ||
with: | ||
java-version: "17" | ||
distribution: "adopt" | ||
|
||
- name: Spring test | ||
run: | | ||
./gradlew clean test | ||
env: | ||
JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY }} | ||
|
||
- name: Upload test results to Codecov | ||
uses: codecov/test-results-action@v1 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
- name: Upload results to Codecov | ||
uses: codecov/codecov-action@v4 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
coverage: | ||
status: | ||
project: | ||
default: | ||
target: 0% # FIXME: Test 완성 후 변경 | ||
patch: | ||
default: | ||
target: 0% # FIXME: Test 완성 후 변경 | ||
|
||
comment: | ||
layout: "header, diff, flags, components, files, footer" | ||
behavior: default | ||
require_changes: false | ||
require_base: false | ||
require_head: false | ||
hide_project_coverage: false | ||
|
||
component_management: | ||
default_rules: | ||
statuses: | ||
- type: project | ||
target: 0% # FIXME: Test 완성 후 변경 | ||
- type: patch | ||
target: 0% # FIXME: Test 완성 후 변경 | ||
individual_components: | ||
- component_id: user | ||
name: user | ||
paths: | ||
- src/test/java/com/server/domain/user/service/** | ||
# TODO: Coverage 측정 제외 대상에 대해 정의 | ||
# ignore: | ||
# - |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
## Spring test 규약 | ||
|
||
- `JUnit`: Java 단위 test framework | ||
- 목적: Code 검증 | ||
- 사용법: `@Test`, `@BeforeEach` 등 annotation으로 test 구성 | ||
- `Mockito`: Mocking library | ||
- 목적: 의존성 격리 | ||
- 사용법: 가짜 객체 생성으로 독립적 test 수행 | ||
- `JaCoCo`: Code coverage 측정 도구 | ||
- 목적: Test coverage 분석 | ||
- 사용법: Test 후 coverage report 제공 | ||
|
||
## Spring test 시 debugging | ||
|
||
1. `@Slf4j` annotation을 추가한다. | ||
|
||
```java | ||
@Slf4j | ||
class UserServiceTest { | ||
``` | ||
|
||
2. 아래와 같이 `--info`를 통해 logger 수준을 설정한다. | ||
|
||
```shell | ||
$ ./gradlew clean test --info | grep ERROR | ||
2025-01-07T21:21:19.197+09:00 ERROR 13537 --- [co-co-gong-server] [ Test worker] c.s.domain.user.service.UserServiceTest : ----------------- | ||
``` | ||
|
||
## JaCoCo | ||
|
||
```shell | ||
$ cd ./build/jacocoHtml && python -m http.server 8000 | ||
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ... | ||
{IP}.{IP}.{IP}.{IP} - - [07/Jan/2025 21:44:45] "GET / HTTP/1.1" 200 - | ||
{IP}.{IP}.{IP}.{IP} - - [07/Jan/2025 21:44:45] "GET /jacoco-resources/report.css HTTP/1.1" 200 - | ||
{IP}.{IP}.{IP}.{IP} - - [07/Jan/2025 21:44:45] "GET /jacoco-resources/sort.js HTTP/1.1" 200 - | ||
{IP}.{IP}.{IP}.{IP} - - [07/Jan/2025 21:44:45] "GET /jacoco-resources/redbar.gif HTTP/1.1" 200 - | ||
{IP}.{IP}.{IP}.{IP} - - [07/Jan/2025 21:44:45] "GET /jacoco-resources/greenbar.gif HTTP/1.1" 200 - | ||
{IP}.{IP}.{IP}.{IP} - - [07/Jan/2025 21:44:45] "GET /jacoco-resources/session.gif HTTP/1.1" 200 - | ||
{IP}.{IP}.{IP}.{IP} - - [07/Jan/2025 21:44:45] "GET /jacoco-resources/report.gif HTTP/1.1" 200 - | ||
{IP}.{IP}.{IP}.{IP} - - [07/Jan/2025 21:44:45] "GET /jacoco-resources/sort.gif HTTP/1.1" 200 - | ||
{IP}.{IP}.{IP}.{IP} - - [07/Jan/2025 21:44:45] "GET /jacoco-resources/down.gif HTTP/1.1" 200 - | ||
{IP}.{IP}.{IP}.{IP} - - [07/Jan/2025 21:44:45] "GET /jacoco-resources/package.gif HTTP/1.1" 200 - | ||
``` | ||
|
||
 | ||
|
||
## [Codecov](https://app.codecov.io/gh/co-co-gong/co-co-gong-server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.