KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hanselexample > ExampleJUnit4Test


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

13 public class ExampleJUnit4Test {
14      
15     @Test public void absTest() {
16         Example example = new Example();
17         assertEquals("abs(1) should be 1.", 1, example.abs(1));
18         assertEquals("abs(-1) should be 1.", 1, example.abs(-1));
19         assertEquals("abs(0) should be 0.", 0, example.abs(0));
20      }
21
22     /**
23      * Test the Example.add() method. This also covers the code of the inner
24      * class.
25      */

26     @Test public void innerClassTest() {
27         Example example = new Example();
28         assertEquals("add(2, 3) should be 5.", 5, example.add(2, 3));
29     }
30 }
31
Popular Tags