• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ExceptionTestCase-error.

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to admit that I don't know how to use ExceptionTestCase - because I don't do.
You could take a look at http://groups.yahoo.com/group/junit/message/8165 and http://groups.yahoo.com/group/junit/message/8166 for some simpler alternatives.
Hope this helps.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic