Tuesday, March 26, 2013

Running JUnit test cases from cmd prompt





Running JUnit test cases from cmd prompt
For Running Junit 4.x test cases from command prompt you should use below command

java -cp C:\lib\junit.jar org.junit.runner.JUnitCore [test class name]

For running Junit 3.x test cases from command prompt you need use below command

java -cp /usr/java/lib/junit.jar junit.textui.TestRunner [test class name]

Example Program

TestCaseA.java

package test; import org.junit.Test; import org.junit.After; import org.junit.Before; public class TestCaseA { @Before public void beforeMethod() { System.out.println("Before method.."); } @Test public void JUnit4Test() { System.out.println("In test method"); } @After public void afterMethod() { System.out.println("after method"); } }

Execution from command prompt

java -cp junit-4.10.jar;test\TestCaseA.class; org.junit.runner.JUnitCore test.TestCaseA




Regards,
SantoshSarma J V




No comments:

Post a Comment

Note: Only a member of this blog may post a comment.