猿问

在 JUnit4 中使用 assertThat

这个链接说函数 assertThat() 在 JUnit4 和 JUnit5 中。

https://www.baeldung.com/junit-assertions

但是,根据创作者团队的JUnit4源代码,assertThat()不包括在内:http ://s.bl-1.com/h/cs6JWS1r?url=https://github.com/junit-team /junit4/tree/master/src/main/java/junit/framework

没有过多使用Maven或JUnit,这些如何调和?我有使用 JUnit4 和 Assert.assertThat 的入门代码,但从源代码来看,assertThat() 不作为函数存在。一个错误证实了这一点。这段代码应该是开箱即用的。


狐的传说
浏览 250回答 1
1回答

动漫人物

代码assertThat包含在此处:https : //github.com/junit-team/junit4/blob/master/src/main/java/org/junit/Assert.java (该包与您正在查看的包不同,所以可能你只是导入错误。)但是,您可能需要将 Hamcrest 库与 JUnit 一起使用assertThat()才能工作,因为您需要适当的Matchers。在您发布的同一页面上,有一个指向此处的链接:https : //www.baeldung.com/java-junit-hamcrest-guide更多细节也在这里:https : //github.com/junit-team/junit4/wiki/matchers-and-assertthat
随时随地看视频慕课网APP

相关分类

Java
我要回答