使用已弃用的 Hamcrest 方法 is() 的替代方法是什么?
我目前使用以下代码对 boolean
值进行断言,但不推荐使用方法 org.hamcrest.Matchers.is()
.
I use the following code at the moment to assert on a boolean
value, however the method org.hamcrest.Matchers.is()
is deprecated.
assertThat(someValue, is(false));
是否有一种简单的替代语法来测试布尔值,而无需求助于 assertTrue()
这会给您提供糟糕的失败消息,例如java.lang.AssertionError"
Is there a simple alternative syntax to test for boolean values without resorting to assertTrue()
which gives you poor failure messages like "java.lang.AssertionError"
在收到评论/回答后编辑
我最初的担忧是因为 Eclipse 显示以下导入语句已被弃用
My initial concerns were raised because Eclipse shows the following import statement as deprecated
关于查看Hamcrest API 文档 is()
方法有 3 种重载变体,其中只有一种已弃用.
On viewing the Hamcrest API docs there are 3 overloaded variations of the is()
method, only one of which is deprecated.
因此,为了澄清@mark 的评论和@matt 的回答,我在上面发布的 is()
的使用是有效的,不会被弃用.
Therefore, to clarify the comment from @mark and the answer from @matt, the use of is()
that I have posted above is valid and not deprecated.
你试过 equalTo(T)
吗?
assertThat(someValue, equalTo(false));
我没有看到 is(T)
已弃用 - is(Class) 已弃用d 但是.
I don't see that is(T)
is deprecated - is(Class) is deprecated however.