【问题标题】:Failed to parse result files when VSTest is run Azure pipelines运行 VSTest 时无法解析结果文件 Azure 管道
【发布时间】:2021-05-07 15:33:13
【问题描述】:

我添加了以下步骤,以便在 Azure 管道中为 React UI 运行单元测试。

添加了一个文件,文件名:jestTrxProcessor.js。内容:

var builder = require("jest-trx-results-processor/dist/testResultsProcessor"); 
var builder = require("jest-trx-results-processor");
 
var processor = builder({
  outputFile: "jestTestresults.trx", 
});
 
module.exports = processor;
  1. 在 package.json 中我输入了以下代码:
"scripts": {
....
"test": "jest"
},
devdependencies{
 ...
 "jest": "^23.4.1",
  "jest-trx-results-processor": "0.0.7",
  "jsdom": "^11.12.0"
},
"jest": {
       "testResultsProcessor": "./__tests__/jestTrxProcessor.js",
    "reporters": [
"default",
[
  "jest-trx-results-processor",
  {
    "outputFile": "./__tests__/jestTestresults.trx",
  
  }
]]},

3.在 yaml 文件中我添加了以下脚本:

- script: |
    npm install
    npm install jest-trx-results-processor --save-dev
    yarn add --dev jest-trx-results-processor
    npm run build
 
   # npm run test
  displayName: 'npm install and build'
  
- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'VSTest'
    testResultsFiles: './__tests__/jestTestresults.trx'
    testRunTitle: 'FrontEnd Test'

我收到以下错误:

【问题讨论】:

    标签: azure-devops yaml azure-pipelines vstest


    【解决方案1】:

    运行 VSTest 时解析结果文件失败 Azure 管道

    根据报错信息:

    发布测试结果无法解析结果文件: System.Xml.XmlException:根级别的数据无效。 1号线, 位置 1

    这意味着您尝试解析不是 XML 文档的内容,或者生成的 trx 文件存在问题。

    要解决此问题,请尝试更新 devdependencies jest jest-trx-results-processor

      "devDependencies": {
        "jest": "^26.6.3",
        "jest-trx-results-processor": "~2.0.0"
      },
    

    并尝试在TestResultsFormat中选择JUnit

    另外Jest testResultsProcessor property is deprecated,请尽量使用jest-junit包做测试报告:

    更多详情请查看this thread

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-31
      • 2021-04-27
      • 2022-07-27
      • 2019-07-19
      • 2020-12-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多