Given the build has an Angular app as part of it, there are Jasmine tests in there. What do I have to do to get those test results published as part of the build and better yet, gate the build result on successful execution of all Jasmine tests?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can do this through the following script and tasks:
- run
ng test
- publish test results with
PublishTestResults
task - publish code coverage results with
PublishCodeCoverageResults
task
In the Azure Pipelines YAML file, this could look as follows:
# 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