단위 테스트 보고서 예시
Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
다양한 언어와 테스트 프레임워크에서 단위 테스트 보고서를 구성하는 가이드로 이 예시들을 참고하세요. 아래 예시들은 .gitlab-ci.yml 파일에 추가할 수 있는 개별 잡 구성을 보여줍니다. 각 예시는 복사하여 프로젝트에 맞게 수정할 수 있는 실제로 동작하는 잡입니다.
다양한 언어와 테스트 프레임워크에서 단위 테스트 보고서를 구성하는 가이드로 이 예시들을 참고하세요. 단위 테스트 보고서를 사용하려면 테스트 프레임워크가 JUnit XML 형식으로 결과를 출력하고 CI/CD 잡이 아티팩트로 결과를 업로드해야 합니다.
아래 예시들은 .gitlab-ci.yml 파일에 추가할 수 있는 개별 잡 구성을 보여줍니다.
모든 예시는 다음을 사용합니다:
- 테스트가 실패할 때도 보고서를 업로드하기 위한
artifacts:when: always. - JUnit XML 파일 위치를 지정하기 위한
artifacts:reports:junit. - 필요한 경우
before_script에서 패키지 설치.
각 예시는 복사하여 프로젝트에 맞게 수정할 수 있는 실제로 동작하는 잡입니다. 다음과 같은 수정이 필요할 수 있습니다:
- 환경에 맞는
image:사양 추가 또는 수정. - 의존성에 맞는 패키지 설치 명령 수정.
- 프로젝트 구조에 맞게 파일 경로 변경.
- 테스트 설정에 맞게 테스트 명령 업데이트.
설정 지침 및 문제 해결은 단위 테스트 보고서를 참조하세요.
도구별 JUnit 출력 구성#
| 언어 | 도구 | JUnit 출력 플래그 |
|---|---|---|
| .NET | JunitXML.TestLogger |
--logger:"junit;LogFilePath=report.xml" |
| C/C++ | GoogleTest | --gtest_output="xml:report.xml" |
| C/C++ | CUnit | CUnitCI.h 매크로로 자동 |
| Flutter/Dart | junitreport |
| tojunit -o report.xml |
| Go | gotestsum |
--junitfile report.xml |
| Helm | helm-unittest |
-t JUnit -o report.xml |
| Java | Gradle | build/test-results/test/에 자동 |
| Java | Maven | target/surefire-reports/ 및 target/failsafe-reports/에 자동 |
| JavaScript | jest-junit |
--reporters=jest-junit |
| JavaScript | karma-junit-reporter |
--reporters junit |
| JavaScript | mocha-gitlab-reporter |
--reporter mocha-gitlab-reporter |
| PHP | PHPUnit | --log-junit report.xml |
| Python | pytest |
--junitxml=report.xml |
| Ruby | rspec_junit_formatter |
--format RspecJunitFormatter --out report.xml |
| Rust | cargo2junit |
| cargo2junit > report.xml |
.NET#
JunitXML.TestLogger NuGet 패키지를 사용하여 .NET으로 JUnit XML 보고서를 생성합니다:
Test:
stage: test
script:
- 'dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=..\artifacts\{assembly}-test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose"'
artifacts:
when: always
paths:
- ./**/*test-result.xml
reports:
junit:
- ./**/*test-result.xml
이 예시는 리포지터리의 루트 폴더에 솔루션이 있고 하위 폴더에 하나 이상의 프로젝트 파일이 있다고 가정합니다. 테스트 프로젝트당 하나의 결과 파일이 생성되며 각 파일은 아티팩트 폴더에 저장됩니다. 형식 인수는 테스트 위젯에서 테스트 데이터의 가독성을 향상시킵니다.
C/C++#
GoogleTest#
내장 XML 출력을 사용하여 GoogleTest로 JUnit XML 보고서를 생성합니다:
cpp:
stage: test
script:
- gtest.exe --gtest_output="xml:report.xml"
artifacts:
when: always
reports:
junit: report.xml
다른 아키텍처 (x86, x64 또는 arm)에 대해 여러 gtest 실행 파일이 생성된 경우
각 테스트의 파일 이름이 고유한지 확인하세요. 그러면 결과가 함께 집계됩니다.
CUnit#
CUnitCI.h 매크로를 사용하여 CUnit으로 JUnit XML 보고서를 생성합니다:
cunit:
stage: test
script:
- ./my-cunit-test
artifacts:
when: always
reports:
junit: ./my-cunit-test.xml
Flutter 또는 Dart#
junitreport 패키지를 사용하여 Flutter 또는 Dart로 JUnit XML 보고서를 생성합니다:
test:
stage: test
script:
- flutter test --machine | tojunit -o report.xml
artifacts:
when: always
reports:
junit:
- report.xml
이 예시는 junitreport 패키지를 사용하여 flutter test 출력을 JUnit 보고서 XML 형식으로 변환합니다.
Go#
gotestsum을 사용하여 Go로 JUnit XML 보고서를 생성합니다:
golang:
stage: test
script:
- go install gotest.tools/gotestsum@latest
- gotestsum --junitfile report.xml --format testname
artifacts:
when: always
reports:
junit: report.xml
Helm#
Helm Unittest 플러그인을 사용하여 Helm으로 JUnit XML 보고서를 생성합니다:
helm:
image: helmunittest/helm-unittest:latest
stage: test
script:
- '-t JUnit -o report.xml -f tests/*[._]test.yaml .'
artifacts:
when: always
reports:
junit: report.xml
-f tests/*[._]test.yaml 플래그는 helm-unittest가 .test.yaml 또는 _test.yaml로 끝나는 파일을 tests/ 디렉토리에서 찾도록 구성합니다.
Java#
Gradle#
내장 테스트 보고를 사용하여 Gradle로 JUnit XML 보고서를 생성합니다:
java:
stage: test
script:
- gradle test
artifacts:
when: always
reports:
junit: build/test-results/test/**/TEST-*.xml
여러 테스트 태스크가 정의된 경우 gradle은 build/test-results/ 아래에 여러 디렉토리를 생성합니다.
이 경우 build/test-results/test/**/TEST-*.xml 경로를 정의하여 글로브 일치를 활용할 수 있습니다.
Maven#
Surefire 및 Failsafe 테스트 보고서를 사용하여 Maven으로 JUnit XML 보고서를 생성합니다:
java:
stage: test
script:
- mvn verify
artifacts:
when: always
reports:
junit:
- target/surefire-reports/TEST-*.xml
- target/failsafe-reports/TEST-*.xml
JavaScript#
Jest#
jest-junit npm 패키지를 사용하여 Jest로 JUnit XML 보고서를 생성합니다:
javascript:
image: node:latest
stage: test
before_script:
- 'yarn global add jest'
- 'yarn add --dev jest-junit'
script:
- 'jest --ci --reporters=default --reporters=jest-junit'
artifacts:
when: always
reports:
junit:
- junit.xml
단위 테스트가 없는 .test.js 파일이 없을 때도 잡이 통과하도록 하려면
script: 섹션의 jest 명령 끝에 --passWithNoTests 플래그를 추가합니다.
Karma#
karma-junit-reporter npm 패키지를 사용하여 Karma로 JUnit XML 보고서를 생성합니다:
javascript:
stage: test
script:
- karma start --reporters junit
artifacts:
when: always
reports:
junit:
- junit.xml
Mocha#
Mocha 구성 예시는 mocha-gitlab-reporter를 참조하세요.
PHP#
PHPUnit을 사용하여 PHP로 JUnit XML 보고서를 생성합니다:
phpunit:
stage: test
script:
- composer install
- vendor/bin/phpunit --log-junit report.xml
artifacts:
when: always
reports:
junit: report.xml
phpunit.xml 구성 파일에서 XML을 사용하여 이 옵션을 구성할 수도 있습니다.
Python#
pytest를 사용하여 Python으로 JUnit XML 보고서를 생성합니다:
pytest:
stage: test
script:
- pytest --junitxml=report.xml
artifacts:
when: always
reports:
junit: report.xml
Ruby#
rspec_junit_formatter gem을 사용하여 RSpec으로 JUnit XML 보고서를 생성합니다:
ruby:
image: ruby:3.0.4
stage: test
before_script:
- apt-get update -y && apt-get install -y bundler
script:
- bundle install
- bundle exec rspec --format progress --format RspecJunitFormatter --out rspec.xml
artifacts:
when: always
paths:
- rspec.xml
reports:
junit: rspec.xml
Rust#
cargo2junit을 사용하여 Rust로 JUnit XML 보고서를 생성합니다:
run unittests:
image: rust:latest
stage: test
before_script:
- cargo install --root . cargo2junit
script:
- cargo test -- -Z unstable-options --format json --report-time | bin/cargo2junit > report.xml
artifacts:
when: always
reports:
junit:
- report.xml
cargo test에서 JSON 출력을 가져오려면 nightly 컴파일러를 활성화해야 합니다.
도구는 현재 디렉토리에 설치됩니다.
