问题
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
来源:https://stackoverflow.com/questions/59977909/running-jasmine-tests-on-azure-devops-as-part-of-automated-build-process