1 package junitour; 2 3 import junit.framework.TestCase; 4 import junit.framework.TestSuite; 5 6 /** 7 * This is a set of TestCases (methods have the prefix: test) 8 * 9 * created: by Hostlowsky, at 31.08.2003 / 21:56:06 10 * <pre> 11 * 12 * $Log$ 13 * Revision 1.4 2004/12/05 04:35:34 hostlows 14 * better javadoc comments, unused imports 15 * 16 * Revision 1.3 2003/12/04 08:59:04 hostlows 17 * new tests 18 * 19 * Revision 1.2 2003/11/25 21:44:15 hostlows 20 * more tests 21 * 22 * Revision 1.1.1.1 2003/11/12 23:32:13 hostlows 23 * Initial import. 24 * 25 * Revision 1.1 2003/10/30 07:13:54 hostlows 26 * First release, which can run as a TextUI-Testrunner and 27 * produces an enhanced output: additionally prints the count of 28 * incomplete Tests! It handles examination of incomplete Testcase over 29 * different classloaders now! 30 * 31 * 32 * </pre> 33 * @author $Author: hostlows $, created by <a href="mailto:hostlows@users.sf.net">Robert Hostlowsky</a> 34 * @version $Revision: 43 $, $Date: 2004-12-05 05:35:34 +0100 (So, 05 Dez 2004) $ 35 */ 36 public class ExampleTest extends TestCase { 37 38 public ExampleTest() { 39 } 40 41 /** failing test case 42 */ 43 public void testFailure() { 44 fail("This test always fails."); 45 } 46 47 48 /** throws an Error to let this test case produce an error 49 * @throws Exception 50 */ 51 public void testThrowsException() throws Exception { 52 throw new Exception("TestCase with produces an error: it throws an Exception."); 53 } 54 55 56 /** results in an assertion/comparison failure 57 */ 58 public void testSimpleFailingComparison() { 59 assertEquals( "b=16, c=15, _just any difference__ d=15, e=5", 60 "b=16, c=15, d=15, e=5" ); 61 } 62 63 /** throws an Error to let this test case produce an error 64 */ 65 public void testThrowsError() throws Error { 66 throw new Error("TestCase with produces an error: it throws an Error."); 67 } 68 69 /** does nothing here: this means that this test case doesn't fail. */ 70 public void testNoFailureOk () { 71 } 72 73 /** throws a Throwable to let this test case produce an error 74 */ 75 public void testThrowsThrowable() throws Throwable { 76 throw new Throwable("TestCase with produces an error: it throws a Throwable."); 77 } 78 79 /** throws a Runtime Exception to let this test case produce an error 80 */ 81 public void testThrowsRuntimeException () throws RuntimeException { 82 throw new RuntimeException("Test, throws a RuntimeException."); 83 } 84 85 /** throws an UnitTestIncompleteError to let this test case produce an failure or 86 * let it be handled with the junitour (marks this test as incomplete! or just ignores it) 87 */ 88 public void testThrowsUnitTestIncompleteError() { 89 throw new UnitTestIncompleteError("TestCase with fails: it throws an UnitTestIncompleteError (derived from AssertionFailedError)."); 90 } 91 92 /** just creates the testsuite object for this class's test methods. 93 * 94 * @return testsuite for this class 95 */ 96 public static TestSuite suite() { 97 return new TestSuite(ExampleTest.class); 98 } 99 100 } 101