How to return exit codes through command line adapter(from Junit test scenarios) to RQM test results
We are using RQM 4.0.3 and command-line adapter to execute Junit test scripts stored in local machine. We are not able to return exit codes from the Junit script to the RQM side.
Sample Junit scenarios we are using are:
Sample Junit script HelloWord.java :
public class HelloWorld {
public String callMe() {
return("Hello World");
}
}
Sample java script TestHelloWorld.java that gives call to HelloWorld.java :
Import junit.framework.TestCase;
public class TestHelloWorld extends TestCase {
public TestHelloWorld(String name) {
super(name);
}
public void testSay() {
HelloWorld sampleObj = new HelloWorld();
assertEquals("Hello World!", sampleObj.callMe());
}
public static void main(String[] args) {
junit.textui.TestRunner.run(TestHelloWorld.class);
}
In these scripts, how to return exit codes.
Thanks in Advance!
3 answers
You need to add System.exit(code) if you want to return the code by Java:
fo example:
public static void main(String[] args) { junit.textui.TestRunner.run(TestHelloWorld.class);
System.exit(2);
}
Please let us know if it helps for you.
Best regards,
Krzysztof Kazmierczyk
1) my +1 on Krzysztof's answer.
2) for a clarification on returned codes, you could check http://pic.dhe.ibm.com/infocenter/clmhelp/v4r0m3/index.jsp?topic=%2Fcom.ibm.rational.test.qm.doc%2Ftopics%2Ft_customize_cmd_line.html
Regards,
Stéphane
Comments
Hi Stephane,
Yes I have checked the article and I tried to return values like 41,42,etc., but some how by default I am seeing only 'passed' state.
Thanks.
Hi Manjunath,
then, if you experience a behavior different from what's described in:
https://jazz.net/library/article/809#MapCodes
you may want to contact Rational support to investigate further.
Regards,
Stéphane
Comments
Hi Ralph,
I have read that blog. The problem is my batch script(.cmd file) is not getting the return value from script( System.exit(41) ). Because when ever I put an echo statement in batch script like "echo errorlevel=%ERRORLEVEL%", it is not showing 41 but by default it is showing errorlevel=0 in result details.
Thanks.