azure - 自动化测试在 Azure 中失败,但该步骤的结果是通过,这是为什么?

标签 azure azure-devops azure-pipelines

我有一套在代码提交时执行的自动化 API 测试。自动化测试运行,但其中许多测试按预期失败。但是,执行测试的步骤会成功返回。因此,整个作业都会成功,这是不正确的行为。

The failed tests but passed step and job

parameters:
- name: testScriptDisplayName
  type: string
- name: testScript
  type: string

trigger:
  branches:
    include:
      - main

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

- script: |
    ls -a
  displayName: 'Explore output directory'
  workingDirectory: '$(Build.Repository.LocalPath)/API/API-Tests'

- script: |
    npm install
    npx playwright install --with-deps
  displayName: "npm install"
  workingDirectory: '$(Build.Repository.LocalPath)/API/API-Tests'

- script: |
    ${{ parameters.testScript }}
    ls -a
  displayName: ${{ parameters.testScriptDisplayName }}
  workingDirectory: '$(Build.Repository.LocalPath)/API/API-Tests'
  failOnStderr: true
  continueOnError: false
  env:
    CI: true

- task: PublishTestResults@2
  displayName: 'Publish test results'
  condition: succeededOrFailed()
  inputs:
    testRunner: JUnit
    testResultsFiles: '**/e2e-junit-results.xml'
    # don't need to use searchFolder
    #searchFolder: 'ts/playwright'

最佳答案

添加failTaskOnFailedTests PublishTestResults 任务的参数,它会将管道标记为失败 - 但仍为您提供测试报告。

- task: PublishTestResults@2
  displayName: 'Publish test results'
  condition: succeededOrFailed()
  inputs:
    testRunner: JUnit
    testResultsFiles: '**/e2e-junit-results.xml'
    failTaskOnFailedTests: true

关于azure - 自动化测试在 Azure 中失败,但该步骤的结果是通过,这是为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76102120/

相关文章:

visual-studio - Visual Studio 2013 - 无法合并 View

azure - 在 Azure DevOps 发布管道中自动创建标签

azure - 如何将 docker 镜像发布为 azure devops 中的工件

java - 有没有办法利用表(azure-storage)客户端 API 通过 CosmosDb 设置项目级别 TTL(生存时间)?

azure - SQL Azure 错误 - TEMPDB 已达到其大小配额

Azure AD - 阻止 guest 访问 Azure 网站

sql-server - 是否可以使用 Azure DevOps 构建任务将 SQL 脚本部署到多个数据库?

regex - git 过滤器分支致命修订

c# - 如何将具有多个组件的应用程序部署到 Azure?

Azure Pipeline 拒绝从 zip 部署,而是从不存在的 blob 调用