使用已弃用的 Hamcrest 方法 is() 的替代方法是什么? [英] What is the alternative to using the Deprecated Hamcrest method is()?

查看:44
本文介绍了使用已弃用的 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.

这篇关于使用已弃用的 Hamcrest 方法 is() 的替代方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆