以下の内容はhttps://doiluxng.hatenablog.com/entry/2018/03/21/153619より取得しました。


Spockで例外をテストするときの注意

例えばこんなメソッドがあって

int convert(String str /* nullかもしれない */ ){
return Optinal.ofNullable(str.length()).orElseThrow( () -> new RuntimeException());
}

Spockのthrownで以下のようなテストをすると通るのでバグに気づかない(NullPointerExceptionはRuntimeExceptionのサブタイプだから)

when:
sut.convert(null)

then:
thrown(RuntimeException)

Spockのthrownを使いたいなら独自RuntimeExceptionを使った方がいいかも。

public class MyAppRuntimeException extends RuntimeException {}



以上の内容はhttps://doiluxng.hatenablog.com/entry/2018/03/21/153619より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14