标签:android 单元测试 断言 assert java
首先看一组对比,比如说我们要测试的结果是一个Linearlaout
AssertJ Android:
assertThat(layout).isVisible()
.isVertical()
.hasChildCount(4)
.hasShowDividers(SHOW_DIVIDERS_MIDDLE);
Regular JUnit:
assertEquals(View.VISIBLE, layout.getVisibility());
assertEquals(VERTICAL, layout.getOrientation());
assertEquals(4, layout.getChildCount());
assertEquals(SHOW_DIVIDERS_MIDDLE, layout.getShowDividers());
Regular AssertJ:
assertThat(layout.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(layout.getOrientation()).isEqualTo(VERTICAL);
assertThat(layout.getChildCount()).isEqualTo(4);
assertThat(layout.getShowDividers()).isEqualTo(SHOW_DIVIDERS_MIDDLE);
从输出结果上看,输出结果更加直接可见。
AssertJ Android: Expected visibility <gone> but was <invisible>
.
Regular JUnit Expected:<[8]> but was:<[4]>
Regular AssertJ: Expected: <8> but was: <4>
标签:android 单元测试 断言 assert java
原文地址:http://blog.csdn.net/yclfdn2004/article/details/40185621