ExceptionTestCase のワナ

junit.extensions.ExceptionTestCase. 最近存在を知ったので試してみようと奮闘してた。



public class Hogehoge extends junit.framework.TestCase {
public static Test suite() {
TestSuite suite = new TestSuite(Hogehoge.class);
suite.addTest(new ExceptionTestCase("exceptionExecute",
Exception.class));

return suite;
}
}




public class Foobar extends ExceptionTestCase {
public exceptionExecute() {
throw new Exception();
}
}

使い方がいまいちわからなくて書いてたコードはこんなの。ちなみに Foobar クラスのコンストラクタは省略。でもそんなメソッドありませんってずっと怒られてた。で気づいた。 Foobar クラスは同じなので省略。



public class Hogehoge extends junit.framework.TestCase {
public static Test suite() {
TestSuite suite = new TestSuite(Hogehoge.class);
suite.addTest(new Foobar("exceptionExecute",
Exception.class));

return suite;
}
}

こうだった。

Eclipse での JUnit 実行に慣れすぎてた弊害か……はじめてだったんだよね suite メソッド書いたの。そのせい。きっと。間違いなく。ええとそういうことにしといてくださいお願いします。

うわぁ恥ずかしい。 font タグなんて使っちゃうくらいに。