AssertJ Fest Hamcrest
生活随笔
收集整理的這篇文章主要介紹了
AssertJ Fest Hamcrest
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
我以前曾在博客中介紹過Hamcrest ,并使用其assertThat方法優先于JUnit的Assert 。
但是,我很快發現了FEST斷言 ,并愉快地切換到它。 它提供了與Hamcrest相同的改進的測試可讀性,并改善了故障消息,但具有啟用IDE自動完成功能的額外好處,而不必搜索軟件包和類文檔以找到合適的匹配器。
不幸的是,Fest似乎不再被積極開發。 1.x分支的最后一個穩定版本1.4于2011年發布,而新的2.x分支從未使其成為穩定版本,并且自2013年6月以來就沒有提交過。
輸入AssertJ …
斷言J
AssertJ是Fest Assert的一個分支 ,并且似乎提供了所有好處以及一系列新功能 。
館藏
例如,它具有我最喜歡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失敗前收集所有錯誤
它還具有在發生故障之前捕獲所有故障的能力。 例如,上述示例將作為第一個失敗的假設而失敗。 下面的示例使您可以查看所有失敗的斷言:
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();并產生如下消息:
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
總結
以上是生活随笔為你收集整理的AssertJ Fest Hamcrest的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 港币符号和美元符号的区别
- 下一篇: 汇率上升是升值还是贬值?