Java JUnit/Hamcrest-org.Hamcrest.CoreMatchers.is()已被弃用。我应该用什么来代替?
方法Java JUnit/Hamcrest-org.Hamcrest.CoreMatchers.is()已被弃用。我应该用什么来代替?,java,junit,junit4,hamcrest,Java,Junit,Junit4,Hamcrest,方法org.hamcrest.CoreMatchers.is()已弃用。 声明使用-org.hamcrest.CoreMatchers.isA() 但是,isA()似乎同时适用于不同的情况 嗯。不管怎样,我的问题来了。前面我使用的是is(),如下所示 // might be i should not be using it like this, but it works. assertThat(actualRes, is(true)); 现在,我不能将这一点用于isA()。它抛出编译错误 不适
org.hamcrest.CoreMatchers.is()已弃用。
声明使用-org.hamcrest.CoreMatchers.isA()
但是,isA()
似乎同时适用于不同的情况
嗯。不管怎样,我的问题来了。前面我使用的是is()
,如下所示
// might be i should not be using it like this, but it works.
assertThat(actualRes, is(true));
现在,我不能将这一点用于isA()
。它抛出编译错误
不适用于参数(布尔值)
我了解isA()的功能。我想知道的是,如果is()
已被弃用,我应该用什么来替代assertThat(actualRes,is(true))
CoreMatchers.is()的弃用形式是:
is(java.lang.Class类型)
不赞成。改用isA(类类型)
因此,对于这个isA
是正确的选择,但是您在这个断言中使用的CoreMatchers.is()
的形式是:assertThat(actualRes,is(true))代码>是
is(T值)
经常使用的快捷方式是(equalTo(x))
。。。这是未弃用的
下面是一些可能会澄清问题的代码:
boolean actualRes = true;
// this passes because the *value of* actualRes is true
assertThat(actualRes, CoreMatchers.is(true));
// this matcher is deprecated but the assertion still passes because the *type of* actualRes is a Boolean
assertThat(actualRes, CoreMatchers.is(Boolean.class));
// this passes because the *type of* actualRes is a Boolean
assertThat(actualRes, CoreMatchers.isA(Boolean.class));
谢谢你的回答。但可悲的是,他说它也被贬值了?我马上就要发疯了。任何进一步的建议都可以恢复我的身份。:-)@samshers我更新了我的答案,简而言之;此方法:is(java.lang.Class type)
已被弃用,但在此断言中未使用该方法:assertThat(actualRes,Matchers.is(true))代码>gr8,明白了。德克萨斯州。