【问题标题】:How to Publish Test Results in Azure DevOps如何在 Azure DevOps 中发布测试结果
【发布时间】:2021-02-27 12:24:52
【问题描述】:

我使用 PublishTestResults 任务创建了以下 YAML 文件,以在 Azure DevOps 门户中显示 mocha 测试结果

# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.14.1'
  displayName: 'Install Node.js'

- script: |
    npm install
    mocha test --reporter mocha-junit-reporter
    npm test
  displayName: 'npm install and test'

- task: PublishTestResults@2
  condition: succeededOrFailed()
  inputs:
    testRunner: JUnit
    testResultsFiles: '**/TEST-RESULTS.xml'

- task: ArchiveFiles@2
  displayName: 'Archive $(System.DefaultWorkingDirectory)'
  inputs:
    rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
    includeRootFolder: false
    archiveFile: '$(Build.ArtifactStagingDirectory)/node.zip'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'

但每当我运行构建时,我都会收到以下警告

"No test result files matching **/TEST-RESULTS.xml were found."

主要目的是在仪表板或测试选项卡中单独显示摩卡测试结果。这样我们就不必在构建过程中检查测试任务来查看测试结果了。

【问题讨论】:

  • 当您在本地运行这些测试时,您认为它创建名为TEST-RESULTS.xml的测试结果文件吗?
  • 是的,它会在我的本地创建一个文件 test-results.xml
  • 嗨@vigneshramesh,PublishTestResults 任务默认搜索路径是$(System.DefaultWorkingDirectory),在下一个任务中,我们可以看到您归档了根文件夹$(System.DefaultWorkingDirectory),请检查 node.zip 文件并确保它包含文件 TEST-RESULTS.xml?请检查它,然后在这里分享结果。
  • 嗨@vigneshramesh,刚刚检查一下这个问题现在是否仍然阻止你?这个问题有什么更新吗?

标签: node.js junit azure-devops mocha.js


【解决方案1】:

我遇到了同样的问题, 尝试了一堆东西后可以解决如下。

步骤 1. 更新 package.json

  1. 包含在scripts 部分:

    "test": "cross-env CI=true react-scripts test --env=jsdom
    --testPathIgnorePatterns=assets --reporters=default --reporters=jest-junit"
    
  2. 在 jest config 中包含以下内容 package.json 中的jest 部分

    "jest-junit": {
        "suiteNameTemplate": "{filepath}",
        "outputDirectory": ".",
        "outputName": "junit.xml"
    }
    

    在本地运行npm run test,看看是否创建了junit.xml

第 2 步。在 Azure Pipeline YAML 文件中

  1. 使用如下自定义命令包含Npm 任务

    - task: Npm@1
      displayName: 'Run Tests'
      inputs:
        command: 'custom'
        workingDir: "folder where your package.json exists"
        customCommand: 'test'
    
  2. 发布结果的任务

    - task: PublishTestResults@2
      displayName: 'Publish Unit Test Results'
      condition: succeededOrFailed()
      inputs:
          testResultsFormat: 'JUnit'
          testResultsFiles: '**/junit.xml'
          mergeTestResults: true
          failTaskOnFailedTests: true
          testRunTitle: 'React App Test'
    

Publish Test Results

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-11
    • 1970-01-01
    • 2021-05-07
    • 2020-06-04
    • 2019-11-09
    • 1970-01-01
    相关资源
    最近更新 更多