fest556_AssertJ Fest Hamcrest
fest556
我以前在博客中介紹過Hamcrest ,并優(yōu)先使用其assertThat方法而不是JUnit的Assert 。
但是,我很快找到了FEST斷言 ,并愉快地切換到它。 它提供了與Hamcrest相同的改進(jìn)的測試可讀性,并改善了故障消息,但具有啟用IDE自動完成功能的額外好處,而不必搜索軟件包和類文檔以找到正確的匹配器。
不幸的是,Fest似乎不再被積極開發(fā)。 1.x分支的最后一個(gè)穩(wěn)定版本1.4于2011年發(fā)布,而新的2.x分支從未使其成為穩(wěn)定版本,并且自2013年6月以來沒有提交過。
輸入AssertJ …
斷言J
AssertJ是Fest Assert的一個(gè)分支 ,它似乎提供了所有好處以及一系列新功能 。
館藏
例如,它具有我最喜歡的Fest的所有精美集合:
List<String> stringList = Lists.newArrayList("A", "B", "C");assertThat(stringList).contains("A"); //trueassertThat(stringList).doesNotContain("D"); //trueassertThat(stringList).containsOnly("A"); //falseassertThat(stringList).containsExactly("A", "C", "B"); //falseassertThat(stringList).containsExactly("A", "B", "C"); //true失敗前收集所有錯(cuò)誤
它還具有在發(fā)生故障之前捕獲所有故障的能力。 例如,上述示例將作為第一個(gè)失敗的假設(shè)而失敗。 下面的示例使您可以查看所有失敗的斷言:
List<String> stringList = Lists.newArrayList("A", "B", "C");SoftAssertions softly = new SoftAssertions();softly.assertThat(stringList).contains("A"); //truesoftly.assertThat(stringList).containsOnly("A"); //falsesoftly.assertThat(stringList).containsExactly("A", "C", "B"); //falsesoftly.assertThat(stringList).containsExactly("A", "B", "C"); //true// Don't forget to call SoftAssertions global verification!softly.assertAll();并產(chǎn)生如下消息:
The following 2 assertions failed: 1) Expecting:<["A", "B", "C"]> to contain only:<["A"]> elements not found:<[]> and elements not expected:<["B", "C"]>2) Actual and expected have the same elements but not in the same order, at index 1 actual element was:<"B"> whereas expected element was:<"C">絕對值得一看。 AssertJ核心代碼和問題跟蹤器托管在github上。
翻譯自: https://www.javacodegeeks.com/2014/10/assertj-fest-hamcrest.html
fest556
總結(jié)
以上是生活随笔為你收集整理的fest556_AssertJ Fest Hamcrest的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《刺客信条 Nexus VR》玩法预告公
- 下一篇: 杭州亚运会《英雄联盟》分组出炉,9 月