使用MSTest插件生成测试报告

问题描述 投票:0回答:1

我正在使用MStest插件时遇到奇怪的效果。我的测试报告仅在测试成功时生成,但是当测试失败时,不会生成测试报告。感谢这个答案,Jenkins integration for dotnet test我的管道看起来像这样

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])

        } 
}

日志:

--- 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

我不知道为什么测试失败时不会生成测试报告。谢谢enter image description here

jenkins jenkins-pipeline jenkins-plugins
1个回答
0
投票

您的测试失败了您的构建,因此您实际上从未实际发布测试结果。

您有两种方法可以解决这个问题 - 将测试配置为在失败的测试中不返回非零状态。

或者忽略它

sh "dotnet test $UnitTest --logger \'trx;LogFileName=unit_tests.xml\' || true"
© www.soinside.com 2019 - 2024. All rights reserved.