如何在Jenkins上为TestCafe测试创建通过阈值

问题描述

我们有testcafe.js UI测试,该测试在Jenkins环境中运行回归套件。

我们正在探索一种创建机制的方法,其中我们可以为测试套件设置一定的通过阈值,以使Jenkins的工作状态为通过/失败。

即如果98%以上的测试通过,则将测试作业标记为通过。

在XUnit项目下,可以使用XUnit测试插件等实现相同的功能。 参考示例:How can I have Jenkins fail a build only when the number of test failures changes?

How to fail a Jenkins job based on pass rate threshold of testng tests

How to not mark Jenkins job as FAILURE when pytest tests fail

通过testcafe定制/通过某些Jenkins插件,基于testcafe的测试是否可能类似?

我们的Jenkins文件

#!groovy

pipeline {
  environment {
    CI = 'true'
  }

  options {
    builddiscarder(logrotator(numToKeepStr: '50'))
    disableResume()
    ansiColor('xterm')
  }

  agent none

  // Define the stages of the pipeline:
  stages {
    stage('setup') {
      steps {
        script {
          cicd.setupBuild()
        }
      }
    }

    // Use the make target to run tests:
    stage('Tests') {
      agent any
      steps {
        script {
          cicd.withSecret(<keys>) {
            cicd.runMake("test")
          }
        }
      }
      post {
        cleanup {
          archiveArtifacts artifacts: "screenshots/**",allowEmptyArchive: true
        }
      }
    }
  }

  post {
    success {
      script { cicd.buildSuccess() }
    }

    failure {
      script {
        slackSend channel: "#<test-notifications-channel>",color: 'bad',message: "Regression tests Failed or unstable <${env.RUN_disPLAY_URL}|${env.JOB_NAME}>"
        cicd.buildFailure()
      }
    }
  }
}
enter code here

解决方法

TestCafe provides一堆指定的报告程序,它们以特殊格式生成报告。一旦生成,CI系统(或其中的插件)就可以分析报告并根据失败/通过的测试次数执行阈值检查。 TestCafe文档包括example with Jenkins integration。该示例中使用的Jenkins JUnit插件尚不支持设置阈值:issue。但是,除了使用Jenkins xUnit插件外,您可以尝试以类似的方式遵循指南中的步骤。