作为自动生成过程的一部分,在Azure DevOps上运行Jasmine测试

时间:2020-01-30 01:25:40

标签: azure-devops jasmine

鉴于该版本包含Angular应用程序,因此其中进行了Jasmine测试。我该怎么做才能将那些测试结果作为构建的一部分发布,并且更好的是,在成功执行所有Jasmine测试之后确定构建结果?

2 个答案:

答案 0 :(得分:5)

您可以通过以下脚本和任务来完成此操作:

  1. 运行ng test
  2. 通过PublishTestResults任务发布测试结果
  3. 使用PublishCodeCoverageResults任务发布代码覆盖率结果

Azure Pipelines YAML文件中,其外观如下:

# perform unit-tets and publish test and code coverage results
- script: |
    npx ng test --watch=false --karmaConfig karma.conf.ci.js --code-coverage
  displayName: 'perform unit tests'    

- task: PublishTestResults@2
  condition: succeededOrFailed()
  inputs:
    testResultsFormat: 'JUnit'
    testResultsFiles: '**/TESTS-*.xml'
  displayName: 'publish unit test results'

- task: PublishCodeCoverageResults@1
  displayName: 'publish code coverage report'
  condition: succeededOrFailed()
  inputs:
    codeCoverageTool: Cobertura
    summaryFileLocation: '$(Build.SourcesDirectory)/coverage/cobertura-coverage.xml'
    failIfCoverageEmpty: true     

答案 1 :(得分:1)

@uminder 的 Azure 配置正确。

我要补充两件事,这样答案就完整了。这是创建 junit 报告和覆盖率文件所必需的 - 以便您以后可以在 azure 管道中引用它们。

  1. junit 和覆盖范围(如果不存在)报告到 karma.config.js
<块引用>
 config.set({
      plugins: [
        ...
        require('karma-coverage'),
        require('karma-junit-reporter')
      ]

当然需要安装

<块引用>

npm install -d karma-junit-reporter

  1. 我还将在 coverageReporter 中添加一个 cobertura 到 karma.config.js

     coverageReporter:  { 
     ....
     reporters: [
         ...
         { type: 'cobertura' } // TO BE ADDED        
     ]
    

    }