LoginSignup
0

More than 3 years have passed since last update.

bitbucket-pipelines テストサマリを表示

Posted at

概要

bitbucket pipelinesではjunitの形式のxmlからテストのサマリを表示することができる。
pipelinesで取得できたサマリーはpipelinesのページに表示される

環境

手順

  • bitbucket pipelinesを使える状態にする

参考
bitbucket pipelines セットアップはこちら

  • golangでjunitの形式でテストのレポートを作成する場合は go-junit-report を使用するのが便利
$ go get -u github.com/jstemmer/go-junit-report 
  • テスト時に特定のディレクトリにレポートを出力することでpipelinesで表示してくれるようになる。以下がpipelinesファイルの例
bitbucket-pipelines.yml
# This is a sample build configuration for Go.
# Check our guides at https://confluence.atlassian.com/x/5Q4SMw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: golang:1.7

pipelines:
  default:
    - step:
        script: # Modify the commands below to build your repository.
          - PACKAGE_PATH="${GOPATH}/src/bitbucket.org/${BITBUCKET_REPO_FULL_NAME}"
          - mkdir -pv "${PACKAGE_PATH}"
          - tar -cO --exclude-vcs --exclude=bitbucket-pipelines.yml . | tar -xv -C "${PACKAGE_PATH}"
          - echo "${GOPATH}"
          - cd "${PACKAGE_PATH}"
          - go get -v
          - go build -v
          - go get -u github.com/jstemmer/go-junit-report
          - mkdir -p "/opt/atlassian/pipelines/agent/build/test-reports/"
          - go test -v 2>&1 | go-junit-report -set-exit-code=1 > /opt/atlassian/pipelines/agent/build/test-reports/junit.xml
  • mkdir -p "/opt/atlassian/pipelines/agent/build/test-reports/" で出力先のディレクトリを作成
  • go test -v 2>&1 | go-junit-report -set-exit-code=1 > /opt/atlassian/pipelines/agent/build/test-reports/junit.xml でjunit形式のレポートを作成したディレクトリに出力する
  • -set-exit-code=1 をgo-junit-reportの実行オプションに指定することで、go test の実行でFAILがあったときに、中断することができる
  • 上記のpipelinesファイルでpipelineが実行された場合、テストの失敗時にビルドが失敗する。(成功時にもレポートに失敗した情報が入っている場合はサマリが表示されるが、コマンドが成功した場合は後段のコマンドが実行されてしまう。)
  • 失敗したテストケースがない場合はサマリは表示されない

成功時

image.png

失敗時

image.png

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0