Go
We'll use gotestsum to generate the JUnit XML reports. gotestsum
runs tests using go test --json
and produces formatted test output, including support for the JUnit XML format.
1. Update your CI workflow to install gotestsum
, create a directory for the JUnit XML files, and then use gotestsum
to run the test suite.
This example project uses Github Actions for CI, so we're updating our CI script in the .github/workflows/
directory, and we're using GitHub Actions syntax.
First, we add a step to the CI workflow to install gotestsum
. Then, before running the test suite, we create a directory for the JUnit XML files. And finally, we replace go test
with the corresponding gotestsum
command. The diff of these changes looks like this:
@@ -14,6 +14,11 @@ jobs:
with:
go-version: '1.16'
+ - name: Set up gotestsum
+ run: |
+ go install gotest.tools/gotestsum@latest
+
- name: Run tests
run: |
- go test ./...
+ mkdir -p tmp/test-results
+ gotestsum --junitfile tmp/test-results/gotestsum-report.xml ./...
If you're using a different CI service, apply the corresponding changes wherever your CI script is defined (e.g., .circleci/config.yml
for CircleCI, etc.).
2. Commit this change to your repository.
git commit -am "Update CI to generate JUnit XML for test results"
The final result of these changes should resemble commit 5e497f6 in the buildpulse-example-go repository.