在 JUnit4 中使用 assertThat
Using assertThat in JUnit4
这 link 表示函数 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() 不作为函数存在。一个错误证实了这一点。此代码应该开箱即用。
此处包含 assertThat
的代码:https://github.com/junit-team/junit4/blob/master/src/main/java/org/junit/Assert.java
(这个包与你正在看的那个不同,所以你可能只是导入了错误的包。)
但是您可能需要将 Hamcrest 库与 JUnit 一起使用才能 assertThat()
工作,因为您需要适当的 Matcher
s.
在您发布的同一页面上有一个 link 到这里:
https://www.baeldung.com/java-junit-hamcrest-guide
更多细节也在这里:https://github.com/junit-team/junit4/wiki/matchers-and-assertthat
这 link 表示函数 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() 不作为函数存在。一个错误证实了这一点。此代码应该开箱即用。
此处包含 assertThat
的代码:https://github.com/junit-team/junit4/blob/master/src/main/java/org/junit/Assert.java
(这个包与你正在看的那个不同,所以你可能只是导入了错误的包。)
但是您可能需要将 Hamcrest 库与 JUnit 一起使用才能 assertThat()
工作,因为您需要适当的 Matcher
s.
在您发布的同一页面上有一个 link 到这里: https://www.baeldung.com/java-junit-hamcrest-guide
更多细节也在这里:https://github.com/junit-team/junit4/wiki/matchers-and-assertthat