調べた範囲だと、JUnit5だと以下のように書くのが一番良さそうだった。
Exception exception = assertThrows(NumberFormatException.class, () -> {
Integer.parseInt("1a");
});
throwされた例外の中もassertできるし、try catchを書かなくて良いし、これいいね。
参考:
調べた範囲だと、JUnit5だと以下のように書くのが一番良さそうだった。
Exception exception = assertThrows(NumberFormatException.class, () -> {
Integer.parseInt("1a");
});
throwされた例外の中もassertできるし、try catchを書かなくて良いし、これいいね。
参考: