DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Get Total Testcase Number in JUnit Report File with grep and awk


Under $JENKINS_HOME/jobs/GSP/workspace/build/work/plugins(we call this folder as "basedir"), there are many bundle folders. Some of them were compiled, so there are many test report file "TEST-.xml" in /build/unittest_report, for example, com.boco.gsp.element.decision.config/build/unittest_report/TEST-com.boco.gsp.decision.config.parser.DecisionParserTest.xml. The content of this file is:

<?xml version="1.0" encoding="UTF-8" ?>

...

In this case the testcase number is 3 according to 'test="3"'. Now we need get the total number of testcases with following steps:

  1. find all these test report file under ${basedir};

  2. get the testcase number;

  3. add all these number up;

  4. print the result;

We achieve this by the following command under ${basedir}:

grep -Po '(?<=tests=")\d+' */TEST-.xml | awk -F':' '{SUM += $2; print $1 ": " $2} END {print "Total: " SUM}'

"-P" let grep interpret pattern as perl regular expression. "-o" means only output the matched part. "(?>=...)" eliminates the text in parenthesis. "-F" of awk specify the delimiter. This command works on zsh because the "*/" syntax only valid on zsh. If you use bash, you have to modify this.



Published

Dec 6, 2013

Last Updated

Dec 6, 2013

Category

Tech

Tags

  • awk 3
  • grep 3
  • shell 46

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor