java – org.junit.Assert.assert好于org.hamcrest.MatcherAsser
我是新来的JUnit和Hamcrest,并希望最佳实践的建议,所以我可以决定哪些文件首先研究.
对于初学者,这些assertThat方法中哪一种更好? > org.junit.Assert.assertThat(from junit-4.11.jar) 据一位去年的一位,“JUnit has the assertThat method,but hamcrest has its own assertThat method that does the same thing.”. 据今年早些时候,Hamcrest “could potentially give better error messages because the matcher is called to describe the mismatch”. 很难说这些帖子比较了哪些版本的Junit和Hamcrest.所以我想要一个基于最新版本的推荐. 解决方法
这是几乎完全相同的事情.
JUnit的最新版本现在包括hamcrest. Infact org.junit.Assert.assertT方法签名是 public static <T> void assertThat(T actual,org.hamcrest.Matcher<T> matcher) 你会注意到使用hamcrest匹配器. 您可能仍然希望包含您自己的hamcrest版本,因为JUnit不是经常更新,并不一定总是使用最新版本的hamcrest. 根据maven pom, 编辑 >当匹配失败时,错误消息包括不同的“预期X但是是Y”.定制hamcrest匹配器可能包括更详细的信息,通过实现describeMismatch() 所以使用org.hamcrest.MatcherAssert.assertThat (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |