0
The jenkins test result GUI shows skipped or expectedFail tests as skipped. The individual test view for skipped or expectedFail tests shows "Skipped Message" and "Standard Output"
e.g. "Skipped Message" can be:
  • a custom skip message
        *  e.g. from python @unittest.skip("some reason") tag or 
        *  e.g. raise unittest.SkipTest("thing not found.")
  • "expected test failure"
  • "xfail-marked test passes unexpectedly"
We are using groovy script to generate test reports. We would like to include more information about skipped tests rather than just "skipped". How can we get info on the skipped test like in the "Skipped Message" in the GUI view?
The jenkins API is documented here:
There is no specific call for getting information on the skipped or expectedFail tests. I am hoping with some experimentation that it will be possible to get expectedFail information through this testResult API. Starting with these API calls:
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.
In the GUI:
  • A normal passed test just has "Standard Output".
  • A normal failed test has "Error Message" and "Stacktrace" and "Standard Output".
  • A skipped or expectedFail tests shows "Skipped Message" and "Standard Output".
We are using python unittest outputting junit test result files. Loading that into jenkins using junit test result plugin.
Have I missed something in the jenkins test results API that would give more information on expected fail or skipped tests ? I hope to find the info through experimentation using the API. And document it in an answer here.
Here is the guts of test report groovy script (used in jenkins Execute Groovy Script plugin after jUnit result plugin has harvested test results):
import hudson.model.*
def build = Thread.currentThread().executable
workspace = build.getEnvVars()["WORKSPACE"]
reportfilename = workspace + "/testreport.html"
rf = new File(reportfilename);


def testCount = "0"
def testPassed = "0"
def testFailed = "0"
def testSkipped = "0"
def buildDuration = "0"

def workspace = "unknown"
def buildName = "unknown"
def BUILD_STATUS = ""
def BUILD_URL = ""

def testResult = null
def testResult1 = null
def testResult2 = null
def testDuration = ""
def caseResult = null

def buildNumber = 0
def buildNumHash = ""
def buildTimeString = ""
def rooturl = ""

try {
    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()["JOB_NAME"]
    BUILD_STATUS = build.getEnvVars()["BUILD_STATUS"]
    BUILD_URL = build.getEnvVars()["BUILD_URL"]

    testResult1 = hudson.tasks.junit.TestResult 
    testResult2 = build.getAction(hudson.tasks.junit.TestResultAction.class)
    caseResult = hudson.tasks.junit.CaseResult

    rooturl = manager.hudson.rootUrl

} catch(Exception ex) {
    rf << "exception accessing build.testResultAction object.";
    //rf << ex;
}

// in groovy the write RE-creates the file, rf << "whatever" is used to append.
rf.write "testreport.groovy #$buildNumber $buildName"

rf << "Summary test report 

\n\
TEST RESULT: $testCount total, $testPassed pass, $testFailed fail, $testSkipped skip.
\n\
Workspace : $workspace
\n\
Project Name : $buildName $buildNumHash

\n\
"

if (build) {

    rf << """\n\
\n\
\n\

\n\

\n\

\n\

\n\

\n\

\n\
\n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ BUILD ${build.result}
Build URL${rooturl}${build.url}
Project:${buildName}
Date of build:${buildTimeString}
Build duration:${build.durationString}
Test duration:${testDuration}
\n\ \n\ """
} if(!testResult) { rf << " No test result " rf << "