1

私はやろうとしていた:

[[[mockQuestion stub] andReturnValue:YES] shouldNegate];
[[[mockQuestion stub] andReturnValue:123] randomNumberWithLimit];

しかし、それは私にこの警告/エラーを与えました「「BOOL」(別名「signed char」)をタイプ「NSValue *」のパラメーターに送信する互換性のない整数ポインター変換」

それを回避するために私が理解できる唯一の方法は、次のことを行うことでした:

BOOL boolValue = YES;
int num = 123;

[[[mockQuestion stub] andReturnValue:OCMOCK_VALUE(boolValue)] shouldNegate];
[[[mockQuestion stub] andReturnValue:OCMOCK_VALUE(num)] randomNumberWithLimit];

しかし、それは私のテストコードが非常に冗長に見える..変数を設定することなく、これをすべてインラインで行う方法はありますか?

4

2 に答える 2

3

You can use a literal style that looks like (type){value}. This is commonly used to create struct literals but works for basic datatypes too. The important aspect here is that this type of literal creates a temporary that can be addressed. This means you can write your code like

[[[mockQuestion stub] andReturnValue:OCMOCK_VALUE((BOOL){YES})] shouldNegate];
[[[mockQuestion stub] andReturnValue:OCMOCK_VALUE((int){123})] randomNumberWithLimit];
于 2012-08-16T23:11:28.033 に答える
0

The parameter is supposed to be an object pointer. In this case it should point to an object of the NSValue class.

于 2012-08-16T23:12:58.703 に答える