Hi ,
pls take a look at the following code
<p><pre>
Pls take a look at the following code:
<code>
import junit.framework.*;
import junit.extensions.*;
import java.util.*;
public class ExceptionTester extends ExceptionTestCase
{
Vector v = null;
public ExceptionTester (
String name,Class exclass)
{
super(name,exclass);
}
protected void setUp() {
v = new Vector(10);
}
public void testIndexOutOfBoundsException() {
System.out.println("Method :: testIndexOutOfBoundsException");
}
protected void runTest() {
System.out.println("Method :: runTest");
testIndexOutOfBoundsException();
}
public static void main(String[] args)
{
ExceptionTestCase
test = new ExceptionTester("testIndexOutOfBoundsException", ArrayIndexOutOfBoundsException.class) ;
junit.textui.TestRunner.run(test);
}
}
</code>
In the above code,testIndexOutOfBounds Exception isnt thrown.However i am not getting an error in
Junit which actuall i must because the ExceptionTestCase tests if a method throws a exception or not.
however if i replace the main method by the following :
<code>
public static void main(String args[]){
ExceptionTestCase test = new ExceptionTester("testIndexOutOfBoundsException", ArrayIndexOutOfBoundsException.class) ;
//junit.textui.TestRunner.run(test);
TestResult result= test.run();
assertEquals(1, result.runCount());
assertEquals(1, result.errorCount());}
</code>
It throws an Error as the method doesnt an Exception.
What the difference in execution of an ExceptionTestCase.
Basically the assertEquals(1,result.errorCount()) is used to check for the presence of absence of errors .
So the Exception Test Case doesnt throw an error directly.
Can you clarify on this ?
</pre>
</p>