2013-04-11 73 views
4

我试图验证一个模拟对象上的函数根本不被任何参数调用。OCMockito验证任何参数

我嘲讽的对象上的功能...

- (void)registerUserWithUsername:(NSString*)username password:(NSString*)password; 

我想验证功能不叫,如果用户名是空白。

[mockService registerUserWithUsername:@"" password:@"Password"]; 

[verify(mockService, never()) registerWithUsername:....... password:.......]; 

我只是不知道该放什么......位?

回答

11

要指定它从来没有叫任何参数,使用anything()匹配:

[verify(mockService, never()) registerWithUsername:(id)anything() password:(id)anything()]; 
+0

真棒的感谢! – Fogmeister 2013-04-14 15:14:32

+0

是否有与原始类型等价的东西? – Zorayr 2016-12-01 22:29:04

+1

@Zorayr请参阅[如何为非对象参数指定匹配器?](https://github.com/jonreid/OCMockito#how-do-you-specify-matchers-for-non-object-arguments) – 2016-12-02 01:01:19