All Downloads are FREE. Search and download functionalities are using the official Maven repository.

junit.extensions.ExceptionTestCase Maven / Gradle / Ivy

Go to download

JUnit is a regression testing framework written by Erich Gamma and Kent Beck. It is used by the developer who implements unit tests in Java.

There is a newer version: 4.13.2
Show newest version
package junit.extensions;

import junit.framework.*;

/**
 * A TestCase that expects an Exception of class fExpected to be thrown.
 * The other way to check that an expected exception is thrown is:
 * 
 * try {
 *   shouldThrow();
 * }
 * catch (SpecialException e) {
 *   return;
 * }
 * fail("Expected SpecialException");
 * 
* * To use ExceptionTestCase, create a TestCase like: *
 * new ExceptionTestCase("testShouldThrow", SpecialException.class);
 * 
*/ public class ExceptionTestCase extends TestCase { Class fExpected; public ExceptionTestCase(String name, Class exception) { super(name); fExpected= exception; } /** * Execute the test method expecting that an Exception of * class fExpected or one of its subclasses will be thrown */ protected void runTest() throws Throwable { try { super.runTest(); } catch (Exception e) { if (fExpected.isAssignableFrom(e.getClass())) return; else throw e; } fail("Expected exception " + fExpected); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy