Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular-cli with VSTS- how to export unit test results in xml format?

I have an application developed with angular-cli. As part of the build process, we run the Unit tests and display the results in VSTS.

How can i generate unit test results in xml format so that i can integrate it with VSTS?

Thanks in advance.

like image 837
user2439903 Avatar asked Nov 07 '17 18:11

user2439903


1 Answers

Assume integrate it with VSTS means using publish test result task to publish your unit test result to VSTS. You could use karma-junit-reporter

karma-junit-reporter is a plugin for Karma that will allow us to get the test output in an XML format so that VSTS can present it for us nicely.

By default, VSTS is able to process JavaScript unit tests in the JUnit format. Karma has a JUnit reporter that can be installed:

npm install karma-junit-reporter --save-dev

This can be added to the Karma config file. Now you can run tests using the --reporters=junit flag and the test run will generate a file named TESTS-browser_(platform).xml.

For example, a local run on Windows 10 creates TESTS-Chrome_54.0.2840_(Windows_10_0.0.0).xml. If you open the file, you’ll see XML that defines the various test cases, how long they ran, and even a structure that holds the console output.

Besides suggest you use PhantomJS a so called Headless Browser for your browser. A headless browser is a browser that is just running in the background, that you can only interact with via code or a terminal.

Finally use ng test command to perform the tests and publish test results:

enter image description here

For more detail info you could take a look at below wonderful blog:

  • Automated Angular Unit Testing on Visual Studio Team Services
  • Integrating Angular 2 Unit Tests with Visual Studio Team Services
like image 112
PatrickLu-MSFT Avatar answered Oct 09 '22 06:10

PatrickLu-MSFT