Integrating Angular test Cases in Azure Pipelines

Viewed 4279

Can anybody provide the information as how we can integrate Angular test cases (Jasmine/Karma) into Azure Pipelines.Where are the test cases result displayed after the build pipeline is executed succesfully

1 Answers

Check case Running Jasmine tests on Azure DevOps as part of automated build process

You can do this through the following script and tasks:

  1. run ng test
  2. publish test results with PublishTestResults task
  3. 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     
Related