Publishing Nx Monorepo Test Results in Azure CI Pipeline

Publish Test Results task publishes test results to Azure CI Pipelines.

Step 1: Publish Unit Test Summary Report

Step 1 - To generate Test Report I’m using Karma JUnit Reporter. First install it to your project.
npm i karma-junit-reporter -D

Step 2 — Now we have to import above ‘karma-junit-reporter’ in to our project and have to configure. So for that, open ‘karma.conf.js’ file in your project. There, in the ‘plugins’ section, add the following line.

Step 3 — Now we have to say use this ‘karma-junit-reporter’ to generate Test Report. For that, in ‘karma.conf.js’ file, you can see a section ‘reporter’. Add the following inside the array.

Step 4 — okay. Now we have said to use JUnit repoter service to generate our Test Report. But to where ? We have to say, where to publish the Test Report. For that, add the following Code Snippet, before the ‘reporters’ section.

junitReporter: { outputDir: 'testresults/junit', outputFile: 'unit-test-result.xml', useBrowserName: false, },

Step 5- In the Azure DevOps Build Pipeline. ‘Publish Test Results’. Click on + symbol and search ‘Publish Test Results’. Add it.

Add below task in your azure-pipelines.yml file. You can skip the condition. I needed that for my Nx Monorepo project. You can just have task and inputs only.

Azure devops task supports merging multiple test results files out of the box. For that we will use mergeTestResults: true flag.

# Publish Test Results # Publish Test Results - task: PublishTestResults@2 inputs: testResultsFormat: 'JUnit' testResultsFiles: '**/testresults/**/*.xml' mergeTestResults: true condition: | and( succeeded(), not(contains( variables['COMMANDS'], '"test":[]' )) )

Test results files created

When you run test now you should see test results file.

In order to avoid check-in them in git repo consider updating .gitignore

# Test Results
testresults/

Running Build in Azure Pipeline


Do You Want to become full stack developer?
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

If you want to become full stack developer and grow your carrier as Lead Developer/Architect. Consider subscribing to our full stack development training programs. We have monthly membership plans and you will get unlimited access to all of our video courses, slides, source code & Monthly video calls.

  • Please visit www.fullstackmaster.net/pro to subscribe to All Access PRO membership.
  • Please visit www.fullstackmaster.net/elite to subscribe to All Access ELITE membership. You will get everything from PRO plan. Additionally you will get access to monthly live Q&A video call with Rupesh and ask doubts and get more tips and tricks.

You bright future is waiting for you so visit today www.fullstackmaster.net and allow me to help you to board on your dream software architect/lead role.


Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Contact Details: Say
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
to me!

Select a repo