Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在jenkins测试结果中的groovy脚本中,我们如何获得跳过测试的信息,以显示测试是预期失败(通过还是失败)还是跳过?_Jenkins_Groovy_Junit_Test Reporting - Fatal编程技术网

在jenkins测试结果中的groovy脚本中,我们如何获得跳过测试的信息,以显示测试是预期失败(通过还是失败)还是跳过?

在jenkins测试结果中的groovy脚本中,我们如何获得跳过测试的信息,以显示测试是预期失败(通过还是失败)还是跳过?,jenkins,groovy,junit,test-reporting,Jenkins,Groovy,Junit,Test Reporting,jenkins测试结果GUI将跳过的或预期的失败测试显示为已跳过。 跳过或预期失败测试的单个测试视图显示“跳过的消息”和“标准输出” e、 g.“跳过的消息”可以是: 自定义跳过消息 * e.g. from python @unittest.skip("some reason") tag or * e.g. raise unittest.SkipTest("thing not found.") “预期测试失败” “xfail标记的测试意外通过” 我们正在使用groo

jenkins测试结果GUI将跳过的或预期的失败测试显示为已跳过。 跳过或预期失败测试的单个测试视图显示“跳过的消息”和“标准输出”

e、 g.“跳过的消息”可以是:

  • 自定义跳过消息

        *  e.g. from python @unittest.skip("some reason") tag or 
        *  e.g. raise unittest.SkipTest("thing not found.")
    
  • “预期测试失败”
  • “xfail标记的测试意外通过”
我们正在使用groovy脚本生成测试报告。 我们希望包含更多关于跳过测试的信息,而不仅仅是“跳过”。 我们如何获得跳过测试的信息,如GUI视图中的“跳过消息”中的信息?

jenkins API的文档记录如下:

对于获取跳过或预期失败测试的信息,没有特定的调用。 我希望通过一些实验,可以通过这个testResult API获得预期的失败信息。 从以下API调用开始:

String  getErrorDetails()
If there was an error or a failure, this is the text from the message.

String  getErrorStackTrace()
If there was an error or a failure, this is the stack trace, or otherwise null.

String  getName()
Gets the name of this object.

String  getStderr()
The stderr of this test.

String  getStdout()
The stdout of this test.

TestResult  getTestResult()
Returns the top level test result data.

String  getTitle()
Gets the human readable title of this result object.
在GUI中:

  • 正常通过的测试只有“标准输出”
  • 正常失败的测试有“错误消息”、“堆栈跟踪”和“标准输出”
  • 跳过或预期失败测试显示“跳过的消息”和“标准输出”
我们正在使用PythonUnitTest输出junit测试结果文件。 使用junit测试结果插件将其加载到jenkins中

我是否遗漏了jenkins测试结果API中的一些内容,这些内容将提供有关预期失败或跳过测试的更多信息? 我希望通过使用API的实验找到这些信息。 并将其记录在这里的答案中

下面是测试报告groovy脚本的核心 (用于jenkins执行Groovy脚本插件 jUnit结果插件获取测试结果后):

导入hudson.model*
def build=Thread.currentThread()可执行文件
workspace=build.getEnvVars()[“workspace”]
reportfilename=workspace+“/testreport.html”
rf=新文件(reportfilename);
def testCount=“0”
def testPassed=“0”
def testFailed=“0”
def testSkipped=“0”
def buildDuration=“0”
def workspace=“未知”
def buildName=“未知”
def BUILD_STATUS=“”
def BUILD_URL=“”
def testResult=null
def testResult1=null
def testResult2=null
def testDuration=“”
def casesult=null
def buildNumber=0
def buildNumHash=“”
def buildTimeString=“”
def rooturl=“”
试一试{
buildNumber=build.number
buildNumHash=build.getDisplayName()
//currentBuildNumber=manager.build.number
buildTimeString=build.getTime().format(“YYYY-MMM-dd-HH:mm:ss”)
if(build.testResultAction){
testResult=build.testResultAction
testCount=String.format(“%d”,(testResult.totalCount))
testPassed=String.format(“%d”,(testResult.result.passCount))
testFailed=String.format(“%d”,(testResult.result.failCount))
testSkipped=String.format(“%d”,(testResult.result.skipCount))
testDuration=String.format(“%.2f”,(testResult.result.duration))
}
workspace=build.getEnvVars()[“workspace”]
buildName=build.getEnvVars()[“作业名称”]
BUILD\u STATUS=BUILD.getEnvVars()[“BUILD\u STATUS”]
BUILD\u URL=BUILD.getEnvVars()[“BUILD\u URL”]
testResult1=hudson.tasks.junit.TestResult
testResult2=build.getAction(hudson.tasks.junit.TestResultAction.class)
casesult=hudson.tasks.junit.casesult
rooturl=manager.hudson.rooturl
}捕获(例外情况除外){

rf我找到了!答案是调用未记录的test.getSkippedMessage()方法。它在源代码中可见

test将跳过消息写入junit xml。 在测试结果中这样标记:

该消息可以是skip()调用中消息的自定义消息,或者在xfail或xpass的情况下,pytest将该消息设置为“预期测试失败”或“xfail标记的测试意外通过”

jenkins junit插件读取junit xml。 该消息可通过以下API获得: 类CaseResult getSkippedMessage() 看见 尽管此处没有记录:

将上述代码的这一部分更改为:

                    if (RESULT == "SKIPPED") { colour = "#ffffb3" }
致:

def moremessage 1=“”;
.
.
.
如果(结果==“跳过”){
color=“#ffffb3”
moremessage1+=“
测试.getSkippedMessage():”+test.getSkippedMessage()+“
” } 射频
                    if (RESULT == "SKIPPED") { colour = "#ffffb3" }
                    def moremessage1 = "";

.
.
.

                    if (RESULT == "SKIPPED") { 
                        colour = "#ffffb3" 
                        moremessage1 += "<br>test.getSkippedMessage():" + test.getSkippedMessage() + "</br>"
                    }

                    rf << "<TR bgcolor='${colour}'><TD class='test' colspan='2'>${highlight1}<li>${RESULT}: ${test.getFullName()} ${moremessage1}</li>${highlight2}</TD></TR>\n"
                    if (RESULT == "SKIPPED") { 
                        colour = "#ffffb3" 
                        moremessage1 += "<br>test.getSkippedMessage():" + test.getSkippedMessage() + "</br>"
                        moremessage1 += "<br>test.getStatus().getMessage():" + test.getStatus().getMessage() + "</br>"
                        moremessage1 += "<br>test.getTitle():" + test.getTitle() + "</br>"
                        moremessage1 += "<br>test.getStdout():" + test.getStdout() + "</br>"
                        moremessage1 += "<br>test.getStderr():" + test.getStderr() + "</br>"
                        moremessage1 += "<br>test.getErrorDetails():" + test.getErrorDetails() + "</br>"
                        moremessage1 += "<br>test.getErrorStackTrace():" + test.getErrorStackTrace() + "</br>"
                        moremessage1 += "<br>test.getName():" + test.getName() + "</br>"
                        moremessage1 += "<br>test.getSafeName():" + test.getSafeName() + "</br>"
                        moremessage1 += "<br>test.getSimpleName():" + test.getSimpleName() + "</br>"
                        moremessage1 += "<br>test.getFullName():" + test.getFullName() + "</br>"
                        moremessage1 += "<br>test.getClassName():" + test.getClassName() + "</br>"
                        moremessage1 += "<br>test.getDisplayName():" + test.getDisplayName() + "</br>"
                        moremessage1 += "<br>test.getPackageName():" + test.getPackageName() + "</br>"