简体   繁体   English

go-junit-report 无法将测试结果解析为 gitlab

[英]go-junit-report failing to parse test results to gitlab

I have a pipeline for my Go project.我的 Go 项目有一个管道。 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.在单元测试的阶段,我使用 go-junit-report 为测试报告生成 xml 文件,该文件应该出现在 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.经过一番搜索,我发现report.xml文件中有非ASCII字符。 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: Remove non-ASCII characters in a file我找到了从文件中删除非 ASCII 字符的解决方案,但不知道如何使其适用于我的情况: 删除文件中的非 ASCII 字符

Here is the script used in the.gitlab-ci.yml 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

The issue was solved in one of the recent commits in go-junit-report.该问题已在 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这解决了这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM