KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hanselexample > ExampleTest


1
2 package org.hanselexample;
3
4 import junit.framework.Test;
5 import junit.framework.TestCase;
6
7 import org.hansel.CoverageDecorator;
8
9 /**
10  * Coverage Test for the Example class.
11  * This test covers all lines (including private/anonymous classes)
12  * of the Example class.
13  *
14  * @author Niklas Mehner
15  */

16 public class ExampleTest extends TestCase {
17     
18     /**
19      * Creates a new Test.
20      * @param name Name of the test.
21      */

22     public ExampleTest(String JavaDoc name) {
23         super(name);
24     }
25
26     /**
27      * Static method to create the TestSuit.
28      * This wrapps the test in a CoverageDecorator.
29      * @return TestSuit for this class.
30      */

31     public static Test suite() {
32         CoverageDecorator cd =
33         new CoverageDecorator(ExampleJUnit4Test.class,
34                               new Class JavaDoc[] { Example.class });
35     
36         cd.setDisplayStatistics(true);
37         return cd;
38     }
39
40     /**
41      * Test the Example.abs() method.
42      */

43     public void testAbs() {
44         Example example = new Example();
45
46         assertEquals("abs(1) should be 1.", 1, example.abs(1));
47         assertEquals("abs(-1) should be 1.", 1, example.abs(-1));
48         assertEquals("abs(0) should be 0.", 0, example.abs(0));
49     }
50
51     /**
52      * Test the Example.add() method. This also covers the code of the inner
53      * class.
54      */

55     public void testInnerClass() {
56         Example example = new Example();
57         assertEquals("add(2, 3) should be 5.", 5, example.add(2, 3));
58     }
59
60 }
61
Popular Tags