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.
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:
For more detail info you could take a look at below wonderful blog:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With