Search This Blog

Sunday, 25 March 2012

Running JUnit 3 from command line

1.) Download Junit 3.

2.) Write a test class :

import junit.framework.TestCase;


public class TestJUnit3 extends TestCase
{
int value1 = 2, value2 = 3, expectedResult = 5;


public void testSuccess()
{
assertTrue(value1 + value2 == expectedResult);
}


public void testFail()
{
assertTrue(value1 - value2 == expectedResult);
}
}


3.) Compile it at from command line :

C:\JavaProgs>javac -cp .;c:\junit\junit3.jar TestJUnit3.java

4.) Run it :

C:\JavaProgs>java -cp .;c:\junit\junit3.jar junit.textui.TestRunner TestJUnit3

This gives below result :

Time: 0
There was 1 failure:
1) testFail(TestJUnit3)junit.framework.AssertionFailedError
at TestJUnit3.testFail(TestJUnit3.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

FAILURES!!!
Tests run: 2, Failures: 1, Errors: 0

No comments:

Post a Comment