Skip to content

docs: Use gotestsum in Unit test reports Go example

What does this MR do?

Change the Go example on https://docs.gitlab.com/ee/ci/unit_test_reports.html to use gotestsum instead of go-junit-report.

go-junit-report has not been updated in over a year. It was written before go test added JSON output and suffers from a few problems that unfortunately make it an unreliable tool in CI.

gotestsum is a better option for a number of reasons:

  1. the go test output is parsed by test2json which is maintained by the Go core team, and is much more widely used (most IDEs use this same parsing). It is much less likely to contain bugs than the custom parsing in go-junit-report (which was written before test2json existed.
  2. by running go test as a subprocess the exit code is always reliable. gotestsum always uses the exit code from go test as its own exit code. From the old example we can see that go-junit-report required a flag to do this, and I believe in some cases even that is unreliable (see next point).
  3. by running go test as a subprocess any build errors sent to stderr can be captured. go-junit-report would miss these errors, and would not be able to properly report the exit status of a test run where some packages failed to build
  4. by running go test as a subprocess, gotestsum is able to format the test output nicely, instead of hiding it all from the user.
  5. in addition to being actively maintained, gotestsum is always more widely used

Author's checklist

To avoid having this MR be added to code verification QA issues, don't add these labels: feature, frontend, backend, ~"bug", or database

Review checklist

Documentation-related MRs should be reviewed by a Technical Writer for a non-blocking review, based on Documentation Guidelines and the Style Guide.

  • If the content requires it, ensure the information is reviewed by a subject matter expert.
  • Technical writer review items:
    • Ensure docs metadata is present and up-to-date.
    • Ensure the appropriate labels are added to this MR.
    • If relevant to this MR, ensure content topic type principles are in use, including:
      • The headings should be something you'd do a Google search for. Instead of Default behavior, say something like Default behavior when you close an issue.
      • The headings (other than the page title) should be active. Instead of Configuring GDK, say something like Configure GDK.
      • Any task steps should be written as a numbered list.
      • If the content still needs to be edited for topic types, you can create a follow-up issue with the docs-technical-debt label.
  • Review by assigned maintainer, who can always request/require the above reviews. Maintainer's review can occur before or after a technical writer review.
  • Ensure a release milestone is set.
Edited by Daniel Nephin

Merge request reports