Write your test case
import junit.framework.TestCase;
public class tests extends TestCase
{
public tests(String s)
{
super(s);
}
public void testA()
{
assertTrue(true);
}
public void testB()
{
assertTrue(false);
}
public void setUp()
{
System.out.println("setUp");
}
public void tearDown()
{
System.out.println("tearDown");
}
}
This is a minimalistic implementation of a test. Notice a few things about this class.
- It implements the junit.framework.TestCase class.
- It provides a constructor that takes a string as its argument.
- It contains a bunch of methods called "test...". These are the test cases.
- It implements methods called setUp() and tearDown(). These methods
are called before and after each test case, and provide convenient places
to initialize and free resources.
- Within the test cases, it uses assertTrue(). This method throws an exception
if its argument evaluates to false. There are several other assertions provided
by the framework, by the junit.framework.Assert class (an ancestor of the TestCase class). In
the class above, testA() will pass and testB() will fail.