Uploading xunit format test

jlvaquerocuevas's Avatar

jlvaquerocuevas

03 Feb, 2020 07:43 AM

I am trying to show the test results in the Test tab in a NodeJs project:

I was able to output xunit format from mocha into a file:

package.json:
"scripts": {
    "start": "node moonBot.js",
    "test": "mocha --reporter xunit > .\\xunit-results.xml"
  }

and in after_test stage I am trying to upload this file using a powershell script as explained here (https://www.appveyor.com/docs/running-tests/#uploading-xml-test-results)

appveyor.yml
after_test:
- ps: >-
    $wc = New-Object 'System.Net.WebClient'

    $wc.UploadFile("https://ci.appveyor.com/api/testresults/xunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\xunit-results.xml))

I got no errors but the Test tab still empty. Can somebody point me to what I am doing wrong?

I am also worry about if the command "mocha --reporter xunit > .\\xunit-results.xml" could hide failed test and appVeyor does not detect it...

  1. Support Staff 1 Posted by Feodor Fitsner on 03 Feb, 2020 06:49 PM

    Feodor Fitsner's Avatar

    Can you send a sample test results XML please?

  2. 2 Posted by jlvaquerocuevas on 04 Feb, 2020 06:47 AM

    jlvaquerocuevas's Avatar

    Of couser. Here you are.

  3. Support Staff 3 Posted by Feodor Fitsner on 04 Feb, 2020 06:01 PM

    Feodor Fitsner's Avatar

    Results look like JUnit test results. Try importing them as "junit" to see if that does the trick.

  4. 4 Posted by jlvaquerocuevas on 05 Feb, 2020 07:11 AM

    jlvaquerocuevas's Avatar

    Yes. You are right. Many thanks. I think I should submit a bug to mocha repo because "--reporter xunit" should output xunit format...

    I have one last question. When tests fail; after_test stage is not executed. Is there some way to upload test in all cases; not just "all test OK" cases?

  5. Support Staff 5 Posted by Feodor Fitsner on 06 Feb, 2020 12:05 AM

    Feodor Fitsner's Avatar

    Sure, you can use on_failure block to execute a logic on failing tests:

    on_failure:
    - echo Do something on failure!
    

    There could be also on_finish block which is called on both successful and failing builds:

    on_finish:
    - echo Do something here...
    
  6. Feodor Fitsner closed this discussion on 07 Apr, 2020 09:02 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac