0

I am currently experiencing a strange effect when using the MStest plugin. My test report is only generated when the test is successful but when it fails, no test report is generated. Thanks to this answer, Jenkins integration for dotnet test my pipeline looks like this

node {
        stage('Checkout') {
            cleanWs()
            checkout scm

            return
            skipRemainingStages = true
        }


        stage('Restore') {

            sh "dotnet restore  $project1"

        }

        stage('Build') {
            sh "dotnet publish $project1 --output $outputFolder --configuration Release -p:Version=$buildVersion -p:FileVersion=$buildVersion"

       }
        stage ('Unit test') {

               sh  "dotnet restore $UnitTest"
               sh returnStdout: true, script: "dotnet test $UnitTest --logger \'trx;LogFileName=unit_tests.xml\' "

               step ([$class: 'MSTestPublisher', testResultsFile:"**/*.xml", failOnError: true, keepLongStdio: true])

        } 
}

The log:

--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Results File: /var/jenkins_home/workspace/myproject/Build_master/myproject/TestResults/unit_tests.xml

Total tests: 16. Passed: 8. Failed: 8. Skipped: 0.
Test Run Failed.
Test execution time: 15.9443 Seconds


[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

I do not know why test reports are not generated when test fails. Thanks enter image description here

hakamairi
  • 4,464
  • 4
  • 30
  • 53
Leroi
  • 349
  • 4
  • 21
  • Could you please attach the stack trace (or log) of the error part? It's not clear what the problem is currently. – hakamairi Feb 28 '19 at 10:55
  • Hi@hakamairi I just edited my post. your can take a look in the code section – Leroi Feb 28 '19 at 11:09
  • thanks for the reply. is it also possible to fail the pipeline and publish results??I would really love to achieve this also because with your answer, the build is marked as unstable. Thanks again for your answer – Leroi Feb 28 '19 at 18:29

1 Answers1

0

Your tests are failing your build so you never actually get to publish the tests results.

You have two ways to tackle this - either configure your tests not to return non zero status on failed tests.

Or ignore it

sh "dotnet test $UnitTest --logger \'trx;LogFileName=unit_tests.xml\' || true"
hakamairi
  • 4,464
  • 4
  • 30
  • 53