junt xmlでテストレポートを保存して履歴とって閲覧する-Gitlab編

自動テストのレポートのデファクトと言ったらjunit reportなんですよ

すごいよね。いまだにjunit xmlがスタンダード。何年現役なんでしょう。多くのciでもこいつをいい感じに見せるビューを備えてる

Gitlab

docs.gitlab.com

junit xmlの出力

playwright.dev

playwright.config.tsdefineConfig.reporter:Array'junit',{outputFile: 'results.xml'}突っ込むか、npx playwright test --reporter=junitするか

個人的に設定に書いちゃうのが多いので今回はその例でやる。好み

htmlは個人的に追加でだしてるだけなんでいらんかったら無視で良し

export default defineConfig({
// other setteings
  reporter: [['junit', { outputFile: 'results.xml' }],["html"]],
// other setteings...

gitlab-ci.yml

artifacts以下が重要。reports書けば各パイプラインのtestsタブにレポートが出るようになる

junit xmlのパスって何?って人はさっきdefineConfigやらに書いたoutputFileやそのあたりにあるファイルを探してください

stages:
  - test

tests:
  stage: test
  image: mcr.microsoft.com/playwright:v1.39.0-jammy
  script:
    - npm install @playwright/test
    - npx playwright test
  artifacts:
    reports:
      junit: results.xml

出力

おまけ mcr.microsoft.com/playwright:v1.39.0-jammy

hub.docker.com

Microsoftって書いてあるけどおもっきしUbuntuイメージ。playwright公式かつmicrosoft公式。

playwrightとブラウザがインストールされたdockerイメージ。npx playwright installとか省略してるのはこれのおかげ。便利。