在 Linux 上使用 GitLab 实现自动化测试
一 架构与准备
二 快速上手示例
stages:
- test
test:
stage: test
image: node:18
script:
- npm ci
- npm test -- --ci
artifacts:
reports:
junit: reports/junit.xml # 需配合测试框架输出 JUnit 报告
stages:
- test
test:
stage: test
image: maven:3-openjdk-21
script:
- mvn test
artifacts:
reports:
junit: target/surefire-reports/TEST-*.xml
stages:
- test
test:
stage: test
image: python:3.11
before_script:
- pip install -r requirements.txt
script:
- pytest --junitxml=reports/pytest.xml
artifacts:
reports:
junit: reports/pytest.xml
要点:使用 image 提供一致环境;通过 artifacts.reports.junit 上传 JUnit XML,在 GitLab 测试报告面板展示用例结果与趋势。
三 常见测试类型与配置要点
前端 E2E(Playwright)
test_e2e:
stage: test
image: mcr.microsoft.com/playwright:v1.44.0-jammy
script:
- npm ci
- npx playwright install --with-deps
- npx playwright test --reporter=junit,html
artifacts:
paths:
- playwright-report/
reports:
junit: reports/playwright-junit.xml
桌面/UI 自动化(Selenium + Allure)
性能测试(JMeter)
四 提升效率与稳定性
五 查看结果与问题排查