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

我的 Go 项目有一个管道。在单元测试阶段,我使用 go-junit-report 为测试报告生成一个 xml 文件,该文件应该出现在 GitLab 的测试选项卡中。

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

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

经过一番查找,我发现report.xml文件中有非ASCII字符。我不确定这是否是测试结果未显示的原因。而且我不确定如何删除它们。我发现此解决方案可从文件中删除非 ASCII 字符,但不知道如何使其适用于我的情况: 删除文件中的非 ASCII 字符

这是 .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


侃侃无极
浏览 143回答 1
1回答

守着一只汪

这个问题在 go-junit-report 中最近的一个提交中得到了解决。更换:go install github.com/jstemmer/go-junit-report/v2@v2.0.0和go install github.com/jstemmer/go-junit-report/v2@934b104ddd2这解决了这个问题
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go