Is there any way to get the number of tests that were executed (or passed) in Jenkins in a Post Job Script (for example, to send this number to the Github Status API)?
I didn't see any way to access these numbers directly from Publish JUnit test result report
Jenkins plug-in.
However, you can always use/parse the xml or json taken form Jenkins REST API after successfully parsing the JUnit XML:
http://<jenkinsHost>/job/<YourJobName>/<JobID>/testReport/api/json?pretty=true
or
to have it more generic:
http://<jenkinsHost>/job/<YourJobName>/lastSuccessfulBuild/testReport/api/json?pretty=true
for JSON output:
{
"duration" : 6109.1104,
"failCount" : 0,
"passCount" : 4389,
"skipCount" : 0,
"suites" : [
{
"cases" : [
{
...
}
],
"duration" : 0.012,
"id" : null,
"name" : "EventTest",
"stderr" : null,
"stdout" : null,
"timestamp" : null
}
]
}
http://<jenkinsInstanceHost>/job/<YourJobName>/<JobID>/testReport/api/xml
for XML output:
<testResult>
<duration>6109.1104</duration>
<failCount>0</failCount>
<passCount>4389</passCount>
<skipCount>0</skipCount>
<suite>
<case>
<age>0</age>
<className>
...
</className>
<duration>0.012</duration>
<failedSince>0</failedSince>
<name>Loop</name>
<skipped>false</skipped>
<status>PASSED</status>
</case>
<duration>0.012</duration>
<name>EventTest</name>
</suite>
</testResult>
I ended up just writing a simple bash scrip that does super simple parsing of the xml produced after running the tests. Using the API as the other answer suggests is a cool idea if you need to do this remotely. In my case, this is the script:
total_tests=$(cat test-reports/*.xml | grep "<testsuite" | tr -s " " | cut -d " " -f6 | cut -d "=" -f2 | sed 's/\"//g' | paste -sd+ - | bc)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With