Tópicos sobre escrita de testes com JUnit/Toy Example (JUnit 3.8.x)
From Wiki**3
The following toy example tests a few situations (some fail, to illustrate all cases). <java5>
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");
}
}
}
</java5>