Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JUnit/Hamcrest-org.Hamcrest.CoreMatchers.is()已被弃用。我应该用什么来代替?_Java_Junit_Junit4_Hamcrest - Fatal编程技术网

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,明白了。德克萨斯州。