test*メソッドを複数定義した場合、テストを実行(Eclipseから実行)するとデフォルトコンストラクタがtest*メソッドの数(テストケースの数)だけ呼び出される。
下記のコードであれば、コンストラクタが3回呼ばれ、もちろん異なるオブジェクトでtest*メソッドが実行されている。
import junit.framework.TestCase; public class JunitTest extends TestCase { private static int SCNT= 0; private int count = 0; public JunitTest() { super(); System.out.println("[create]" + this.hashCode()); } public void testA() { write(); } public void testB() { write(); } public void testC() { write(); } private void write() { System.out.println("[" + SCNT++ + "][" + this.count++ + "]" + this.hashCode()); } }
[create]19581314 [create]1280484 [create]12717604 [0][0]19581314 [1][0]1280484 [2][0]12717604