Test counts after different jobs run, some fails, retry jobs seem to be messed up.
groovy == javascript/java syntax
Test report script derived from one provided with plugin in jenkins similar to here:
https://stackoverflow.com/questions/39920437/how-to-access-junit-test-counts-in-jenkins-pipeline-project
Guts of script here: (see below)
https://stackoverflow.com/questions/59631365/in-groovy-script-in-jenkins-test-result-how-can-we-get-information-on-skipped-te
Added answer here. Yes. Is bug. Seen that.
https://stackoverflow.com/questions/17208476/long-duration-on-jenkins-skipped-tests/59631492#59631492
Added answer here. Just make a test fail. Or can use groovy set build description, could set background/badge test or icon also in groovy with badge plugin:
https://stackoverflow.com/questions/15482846/can-i-make-skipped-tests-more-prominent-in-the-jenkins-dashboard/59632047#59632047
jenkins example of build badge in test description (visible in job history or job page or different build monitoring views) |
https://stackoverflow.com/questions/52870325/format-string-in-groovy
s = String.format("foo i:%d s:%s", 42, "foobar")
https://javadoc.jenkins.io/plugin/junit/hudson/tasks/junit/TestResult.html
http://hudson-ci.org/javadoc/hudson/tasks/test/TestResult.html
https://stackoverflow.com/questions/59631365/in-groovy-script-in-jenkins-test-result-how-can-we-get-information-on-skipped-te
Asked
Viewed 1 times
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\
BUILD ${build.result}
\n\
Build URL ${rooturl}${build.url}
\n\
Project: ${buildName}
\n\
Date of build: ${buildTimeString}
\n\
Build duration: ${build.durationString}
\n\
Test duration: ${testDuration}
\n\
\n\
\n\
"""
}
if(!testResult) {
rf << "
No test result
"
rf << "
test result from build.testResultAction" } else { junitResultList.add(testResult2.getResult()) if (junitResultList.size() > 0) { rf << "
test result from build.getAction" } else { rf << "
No results in 'testResult2'
\n" junitResultList.add(testResult1.getResult()) } } //rf << "
DEBUG" + junitResultList.size() + " test items" // API: http://hudson-ci.org/javadoc/hudson/tasks/junit/PackageResult.html rf << "\n" if (junitResultList.size() > 0) { rf << '
\n' } rf << "testreport.groovy\n"
No comments:
Post a Comment