go-junit-report无法解析测试结果到GitLab。

huangapple go评论65阅读模式
英文:

go-junit-report failing to parse test results to gitlab

问题

我有一个用于我的Go项目的流水线。在单元测试阶段,我使用go-junit-report生成一个XML文件,用于在GitLab的测试选项卡中显示测试报告。

由于某种原因,测试结果不再显示,并显示以下错误消息:

JUnit XML解析失败:9:25:FATAL:未注册的错误消息

经过一些搜索,我发现report.xml文件中存在非ASCII字符。我不确定这是否是测试结果不显示的原因。我也不知道如何删除它们。我在这里找到了一个解决方案,可以从文件中删除非ASCII字符,但不知道如何在我的情况下使其工作:
https://stackoverflow.com/questions/3264915/remove-non-ascii-characters-in-a-file

这是在.gitlab-ci.yml文件中使用的脚本:

test:
  stage: build
  artifacts:
    when: always
    expire_in: 30 day
    reports:
      junit: report.xml
  script:
    - go install github.com/jstemmer/go-junit-report/v2@v2.0.0
    - go test -cover -v ./internal/... -coverprofile=unit.coverprofile -tags=unit \
      | $GOPATH/bin/go-junit-report -iocopy -set-exit-code -out report.xml

英文:

I have a pipeline for my Go project. In stages for the unit tests, i use go-junit-report to generate a xml file for test reports which are supposed to appear in the tests tab on GitLab.

For some reason test results stopped showing up, with the following error message:

JUnit XML parsing failed: 9:25: FATAL: Unregistered error message

After some searching, I discovered that there are non-ASCII characters in the report.xml file. I'm not sure if it's the reason for the test results not showing up. And I'm not sure how to remove them. I found this solution to remove non-ASCII characters from the file, but don't know how to make it work in my case:
https://stackoverflow.com/questions/3264915/remove-non-ascii-characters-in-a-file

Here is the script used in the .gitlab-ci.yml file:

test:
  stage: build
  artifacts:
    when: always
    expire_in: 30 day
    reports:
      junit: report.xml
  script:
    - go install github.com/jstemmer/go-junit-report/v2@v2.0.0
    - go test -cover -v ./internal/... -coverprofile=unit.coverprofile -tags=unit \
      | $GOPATH/bin/go-junit-report -iocopy -set-exit-code -out report.xml

答案1

得分: 2

这个问题在最近的提交中已经解决了。将以下内容替换:

go install github.com/jstemmer/go-junit-report/v2@v2.0.0

改为:

go install github.com/jstemmer/go-junit-report/v2@934b104ddd2

这样就解决了这个问题。

英文:

The issue was solved in one of the recent commits in go-junit-report.
Replacing:

go install github.com/jstemmer/go-junit-report/v2@v2.0.0

With

go install github.com/jstemmer/go-junit-report/v2@934b104ddd2

This solves this issue

huangapple
  • 本文由 发表于 2022年9月15日 20:38:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/73731299.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定