단위 테스트 보고서 예제
단위 테스트 보고서는 많은 언어와 패키지에 대해 생성될 수 있습니다.
이러한 예제를 파이프라인을 구성하여 나열된 언어 및 패키지에 대한 단위 테스트 보고서를 생성하는 가이드라인으로 사용하세요.
사용 중인 언어 또는 패키지의 버전에 맞게 예제를 편집해야 할 수도 있습니다.
루비
다음 작업을 .gitlab-ci.yml
에 추가하세요.
이 작업에는 단위 테스트 보고서 출력 파일에 대한 링크를 제공하기 위해 artifacts:paths
키워드가 포함되어 있습니다.
## https://github.com/sj26/rspec_junit_formatter를 사용하여 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
고
다음 작업을 .gitlab-ci.yml
에 추가하세요:
## https://github.com/gotestyourself/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
자바
JUnit 보고서 형식 XML 파일을 생성할 수 있는 몇 가지 도구가 있습니다.
Gradle
다음 예제에서는 gradle
을 사용하여 테스트 보고서를 생성합니다.
여러 테스트 작업이 정의된 경우 gradle
은 build/test-results/
아래에 여러 디렉터리를 생성합니다.
이 경우 다음 경로를 정의하여 glob 매칭을 활용할 수 있습니다: build/test-results/test/**/TEST-*.xml
:
java:
stage: test
script:
- gradle test
artifacts:
when: always
reports:
junit: build/test-results/test/**/TEST-*.xml
GitLab Runner 13.0
이후 버전에서 **
를 사용할 수 있습니다.
Maven
Surefire
및 Failsafe 테스트 보고서를 구문 분석하려면
다음 작업을 .gitlab-ci.yml
에 추가하세요:
java:
stage: test
script:
- mvn verify
artifacts:
when: always
reports:
junit:
- target/surefire-reports/TEST-*.xml
- target/failsafe-reports/TEST-*.xml
파이썬 예제
이 예제는 pytest를 사용하여 출력 형식을 JUnit 보고서 XML 형식으로 포맷합니다.
--junitxml=report.xml
플래그를 사용합니다:
pytest:
stage: test
script:
- pytest --junitxml=report.xml
artifacts:
when: always
reports:
junit: report.xml
C/C++
C/C++에서 JUnit 보고서 형식 XML 파일을 생성할 수 있는 몇 가지 도구가 있습니다.
GoogleTest
다음 예제에서 gtest
는 테스트 보고서를 생성하는 데 사용됩니다.
여러 아키텍처(x86
, x64
또는 arm
)에 대해 생성된 gtest
실행 파일이 있는 경우,
각 테스트를 고유한 파일 이름을 제공하여 실행해야 합니다. 결과는 함께 집계됩니다.
cpp:
stage: test
script:
- gtest.exe --gtest_output="xml:report.xml"
artifacts:
when: always
reports:
junit: report.xml
CUnit
CUnit은 CUnitCI.h
매크로를 사용하여 자동으로 JUnit 보고서 형식 XML 파일을 생성할 수 있습니다:
cunit:
stage: test
script:
- ./my-cunit-test
artifacts:
when: always
reports:
junit: ./my-cunit-test.xml
.NET
JunitXML.TestLogger NuGet 패키지는 .Net Framework 및 .Net Core 애플리케이션에 대한 테스트 보고서를 생성할 수 있습니다.
다음 예제는 저장소의 루트 폴더에 솔루션이 있고, 서브폴더에 하나 이상의 프로젝트 파일이 있다고 예상합니다.
테스트 프로젝트당 하나의 결과 파일이 생성되며, 각 파일은 아티팩트 폴더에 배치됩니다.
이 예제에는 테스트 위젯에서 테스트 데이터의 가독성을 개선하는 선택적 형식 지정 인수가 포함되어 있습니다.
전체 .Net Core 예제는 여기에서 사용할 수 있습니다.
## 소스 코드 및 문서는 여기에 있습니다: https://github.com/spekt/junit.testlogger/
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
JavaScript
JavaScript에서 JUnit 보고서 형식 XML 파일을 생성할 수 있는 몇 가지 도구가 있습니다.
Jest
jest-junit npm 패키지는 JavaScript 애플리케이션에 대한 테스트 보고서를 생성할 수 있습니다.
다음 .gitlab-ci.yml
예제에서 javascript
작업은 Jest를 사용하여 테스트 보고서를 생성합니다:
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 패키지는 JavaScript 애플리케이션에 대한 테스트 보고서를 생성할 수 있습니다.
다음 .gitlab-ci.yml
예제에서 javascript
작업은 Karma를 사용하여 테스트 보고서를 생성합니다:
javascript:
stage: test
script:
- karma start --reporters junit
artifacts:
when: always
reports:
junit:
- junit.xml
Mocha
JUnit Reporter for Mocha NPM 패키지는 JavaScript 애플리케이션에 대한 테스트 보고서를 생성할 수 있습니다. 다음 .gitlab-ci.yml
예제에서 javascript
작업은 Mocha를 사용하여 테스트 보고서를 생성합니다:
javascript:
stage: test
script:
- mocha --reporter mocha-junit-reporter --reporter-options mochaFile=junit.xml
artifacts:
when: always
reports:
junit:
- junit.xml
Flutter 또는 Dart
이 예제 .gitlab-ci.yml
파일은 JUnit Report 패키지를 사용하여 flutter test
출력을 JUnit 보고서 XML 형식으로 변환합니다:
test:
stage: test
script:
- flutter test --machine | tojunit -o report.xml
artifacts:
when: always
reports:
junit:
- report.xml
PHP
이 예제는 PHPUnit와 --log-junit
플래그를 사용합니다. 이 옵션은 phpunit.xml
구성 파일의 XML에서 추가할 수도 있습니다.
phpunit:
stage: test
script:
- composer install
- vendor/bin/phpunit --log-junit report.xml
artifacts:
when: always
reports:
junit: report.xml
Rust
이 예제는 cargo2junit를 사용하며, 현재 디렉토리에 설치됩니다. cargo test
에서 JSON 출력을 얻으려면 야간 컴파일러를 활성화해야 합니다.
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
Helm
이 예제는 Helm Unittest 플러그인을 사용하며, 출력 형식을 JUnit 보고서 XML 형식으로 설정하기 위해 -t junit
플래그를 사용합니다.
helm:
image: helmunittest/helm-unittest:latest
stage: test
script:
- '-t JUnit -o report.xml -f tests/*[._]test.yaml .'
artifacts:
reports:
junit: report.xml
-f tests/*[._]test.yaml
플래그는 helm-unittest
가 tests/
디렉토리에서 다음 중 하나로 끝나는 파일을 찾도록 구성합니다:
.test.yaml
_test.yaml