sam*_*ers 4 java junit hamcrest junit4
该方法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));
Run Code Online (Sandbox Code Playgroud)
现在我不能使用相同的isA()
. 它引发编译错误不适用于参数(布尔值)
我明白是isA()
做什么的。我想知道的是,鉴于is()
已弃用,我应该使用什么来替代assertThat(actualRes, is(true))
?
的弃用形式CoreMatchers.is()
是这样的:
is(java.lang.Class 类型)
已弃用。使用 isA(Class type) 代替。
因此,对于这isA
是正确的选择,但形式CoreMatchers.is()
,其使用的是这句话:assertThat(actualRes, is(true));
就是这一个...
是(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));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3887 次 |
最近记录: |