繁体   English   中英

在JUnit4中使用assertThat

[英]Using assertThat in JUnit4

该链接表示函数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 /树/主/ SRC /主/爪哇/ junit的/框架

没有过多使用Maven或JUnit,这些如何协调? 我有使用JUnit4和Assert.assertThat的入门代码,但是从源代码中可以看出,assertThat()作为函数不存在。 错误确认这一点。 该代码应该开箱即用。

assertThat的代码包含在这里: https : //github.com/junit-team/junit4/blob/master/src/main/java/org/junit/Assert.java (该包与您所寻找的包不同)在,因此您可能导入错误。)

但是,您可能需要将Hamcrest库和JUnit一起使用,以使assertThat()起作用,因为您需要适当的Matcher

在您发布的同一页上,有一个指向此处的链接: https : //www.baeldung.com/java-junit-hamcrest-guide

这里也有更多细节: https//github.com/junit-team/junit4/wiki/matchers-and-assertthat

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM