dcsimg
ExceptionTestCase usage
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Naveen_N
Posted On:   Friday, September 5, 2003 09:06 AM

Pls take a look at the following 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"); testIndexOutOfBoundsExcept   More>>

			
Pls take a look at the following 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);

}

}


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 :

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());}

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 ?

   <<Less
About | Sitemap | Contact