SE450: JUnit: Writing A Test [32/41] ![]() ![]() ![]() |
How do you write a test?
assertTrue and pass in a boolean that is
true if the test is successful. You can also use a form of one
of the assertEquals, assertFalse, assertNotNull, assertNull
assertSame, or assertNotSame from the
Assert class.
(Part of) an example that tests the java.util.Vector class.
import junit.framework.*;
import java.util.Vector;
/**
* A sample test case, testing <code>java.util.Vector</code>.
*
*/
public class VectorTest extends TestCase {
public VectorTest(String name) {
super(name);
}
public void testCapacity() {
Vector fEmpty;
Vector fFull;
int size= fFull.size();
for (int i= 0; i < 100; i++)
fFull.addElement(new Integer(i));
assertTrue(fFull.size() == 100+size);
}