단위 테스트 보고서 예시
Unit test reports는 여러 언어와 패키지에 대해 생성할 수 있습니다. 파이프라인을 구성하여 단위 테스트 보고서를 생성하도록 파이프라인을 구성하는 지침으로 이러한 예시를 사용하세요. 나열된 언어 및 패키지에 대한 언어 또는 패키지 버전과 일치하도록 예시를 편집해야 할 수도 있습니다.
루비
.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
Go
.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
Java
Java에서 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와 --junitxml=report.xml
플래그를 사용하여 출력을 JUnit 보고서 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
.Net Framework 및 .Net Core 응용 프로그램을 위한 테스트 보고서를 생성할 수 있는 JunitXML.TestLogger NuGet 패키지가 있습니다. 다음 예시에서는 저장소의 루트 폴더에 솔루션이 있으며, 서브 폴더에 하나 이상의 프로젝트 파일이 있는 것으로 가정합니다. 각 테스트 프로젝트 당 하나의 결과 파일이 생성되며 각 파일은 artifacts 폴더에 위치합니다. 이 예시에는 테스트 데이터의 가독성을 향상시키는 선택적 포맷 매개변수가 포함되어 있습니다. 전체 .Net Core 예시를 참조하세요.
## 소스 코드 및 문서는 여기에서 확인할 수 있습니다: [https://github.com/spekt/junit.testlogger/](https://github.com/spekt/junit.testlogger/)
### JavaScript
자바스크립트에서 JUnit 보고서 형식의 XML 파일을 생성할 수 있는 몇 가지 도구가 있습니다.
#### Jest
[jest-junit](https://github.com/jest-community/jest-junit) npm 패키지는 JavaScript 애플리케이션을 위한 테스트 보고서를 생성할 수 있습니다. 다음 `.gitlab-ci.yml` 예제에서 `javascript` 작업은 Jest를 사용하여 테스트 보고서를 생성합니다:
```yaml
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
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
파일은 flutter test
출력을 JUnit 보고서 XML 형식으로 변환하기 위해 JUnit Report 패키지를 사용합니다:
test:
stage: test
script:
- flutter test --machine | tojunit -o report.xml
artifacts:
when: always
reports:
junit:
- report.xml
PHP
이 예제는 --log-junit
플래그와 함께 PHPUnit을 사용합니다. 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 출력을 가져오려면 nightly 컴파일러를 활성화해야 합니다.
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 플러그인을 사용하여 -t junit
플래그로 출력을 JUnit 보고서의 XML 형식으로 포맷합니다.
helm:
image: helmunittest/helm-unittest:latest
stage: test
script:
- '-t JUnit -o report.xml -f tests/*[._]test.yaml .'
artifacts:
reports:
junit: report.xml