Expect
は、JUnit @Rule
として使用することを意図しています。テストが終了した後にAssertionError
がスローされたことをソースコードで確認すると、rule's apply()
methodになります。ここではそれが何をするかの簡易版だ:
public void evaluate() throws Throwable {
// this invokes the test, collecting failures in gatherer
base.evaluate();
// after the test finishes the failures are collected and thrown
if (!gatherer.getMessages().isEmpty()) {
throw new AssertionError(gatherer.toString());
}
}
example usage of Expect
は、(よりよい文書化の別の場所であってはならないと言っているのではない)ユニットテストであります。基本的に、同じように行を追加します。
は
@Rule public final Expect expect = Expect.create();
その後、代わりにテストが完了したら失敗し、テストがフェイルファストことはありませんfoo
に関するアサーションを作るためにexpect.that(foo)....
を使用しています。