Assert 斷言 - assertj, truth

assertj-android

  • 註: 筆者 2013 下旬發現
  • 註: 2013 上旬仿 AssertJ 以 fest-android 名稱釋出,2014 中旬正式加入 AssertJ 家族,更名為 assertj-android
  • 註: assertj 2011 釋出

針對 Android 的類別作語法撿結語錯誤訊息的強化。

語法的簡潔:

Before(JUnit):

assertEquals(View.GONE, view.getVisibility());

After(AssertJ):

assertThat(view).isGone();

錯誤訊息的強化:

Before(JUnit):

Expected:<[8]> but was:<[4]>

After:

Expected visibility <gone> but was <invisible>

truth

  • 註: 筆者是在 2015/2 留意到它
  • 註: 2014/12 由 google testing blog 消息釋出
  • 仿 AssertJ

在沒有特定的類別下,提供一個置換錯誤訊息的能力。

Before(JUnit):

boolean buttonEnabled = false;
assertTrue(buttonEnabled);

After(truth):

ASSERT.that(buttonEnabled).named("buttonEnabled").isTrue();

錯誤訊息的強化:

Before(JUnit):

<false> was expected be true, but was false

After(truth):

"buttonEnabled" was expected to be true, but was false

assertj-rx

assertThat(observable.toBlocking()).completes();
assertThat(observable.toBlocking())
    .completes()
    .emitsSingleValue("hello");
assertThat(observable.toBlocking()).fails();

Hamcrest

See Also