Line 11: | Line 11: | ||
} | } | ||
− | public void | + | public void testCreativeMultiplication() { |
// Testing if 3*2=6: | // Testing if 3*2=6: | ||
assertEquals("Creative multiplication", 7, 3*2); | assertEquals("Creative multiplication", 7, 3*2); |
The following toy example tests a few situations (some fail, to illustrate all cases).
import junit.framework.*; import java.util.ArrayList; public class HelloWorld3 extends TestCase { public void testMultiplication() { // Testing if 3*2=6: assertEquals("Multiplication", 6, 3*2); } public void testCreativeMultiplication() { // Testing if 3*2=6: assertEquals("Creative multiplication", 7, 3*2); } public void testException1() { try { ArrayList<Object> emptyList = new ArrayList<Object>(); Object o = emptyList.get(0); // throws IndexOutOfBoundsException fail("no exception"); } catch (Exception e) { } } public void testException2() { try { int i = 0; } catch (Exception e) { fail("exception"); } } }