Maven Goals To Execute Commands Post Test Executionadmin
Recently in one of the projects we got the requirement to create the test execution summary file after parsing the TestNG emailable report once the test execution is finished.
We were running the test with Maven goal which generates the emailable report in target directory of the project but it does it once build is completed due to which we were not able to write the parsing code in TestNG listener.
We have written the code for parsing the emailable report (Check our other blogs for it) in a class having main() method.
We have used below maven plugin and provided our class which contains the required code.
<mainClass>Class file containing main method</mainClass>
Now we can execute tests using below command
mvn -X clean install test exec:java -Dexec.mainClass=”class file containing with main method” -Dexec.classpathScope=test -e -Dsurefire.suiteXmlFiles=path of the testng.xml file
IMPORTANT: Above goal will not execute if there is any test failure as it will mark the build as failed so to execute above goal even on build failure add below configuration in the surefire plugin