Download Wiley - Java Tools for Extreme Programming

Transcript
4. If we need to release resources that were part of the fixture, override the tearDown() method.
5. If we need to group a related set of test cases, define a suite of tests.
The next section discusses writing your own test case based on java.util. HashMap.
Writing a Test Case
An excellent example of creating a test case is provided in the samples that ship with JUnit. The example is
called VectorTest, and it shows how you would go about writing a test case for java.util.Vector. The good thing
about this example is that most people are familiar with the Vector class. In the same spirit, we created a
simple example based on the java.util.HashMap (Listing 7.1). We will go through this example step by step.
Listing 7.1: HashMapTest Test Case Example.
/*
* HashMapTest.java
*
* Created on September 16, 2001, 12:27 PM
*/
package xptoolkit.junit.example;
import junit.framework.*;
import java.util.Map;
import java.util.HashMap;
import junit.extensions.*;
/**
*
* @author Rick Hightower
* @version 1.0
*/
public class HashMapTest extends TestCase {
private Map testMap;
private Map testMap2;
public HashMapTest(String name) {
super(name);
}
158