Problems using (verifying) mock objects more than once
Problems using (verifying) mock objects more than once
- Subject: Problems using (verifying) mock objects more than once
- From: Jeremy Higgs <email@hidden>
- Date: Mon, 9 Jan 2006 23:16:59 +1100
Hi,
I'm currently trying to unit test some messy NSTableView data source
code using OCUnit and OCMock, but am running into problems when I
"verify" the mock objects more that once.
I'm trying to replicate what happens when the table view selection
changes, in which the selected indexes are cached in the
tableViewSelectionDidChange: delegate method.
Here is some example code:
// Setup the class and the mock
mockAnotherController = [OCMock mockForClass:[AnotherController class]];
controller = [[SomeController alloc] init];
[controller setAnotherController:mockAnotherController];
// First time round
[[mockAnotherController expect] foo:[NSArray array] bar:1]; // Not
really the arguments, but you get the point
[controller someMethod]; // This calls the foo:bar: method in
mockAnotherController
[mockAnotherController verify]; // This passes fine
// Second time round
[[mockAnotherController expect] foo:[NSArray array] bar:1]; // Exact
same arguments as before
[controller performSelector:@selector(tableViewSelectionDidChange:)
withObject:nil]; // Call the delegate method
[mockAnotherController verify]; // This fails
The test failure that is reported is:
"Did not call expected method [OCMockObject: ..."
I have placed NSLogs before and after the call to the
mockAnotherController method, and they all print (which means it's
gone past the line with the method call). Additionally, the
mockAnotherController object is not nil. This leads me to believe that
once the mock object has been "verified", additional expectations
placed on it don't seem to work. Has anyone else noticed this?
If that's the case, is there a way to reset the mock object "recorder"
once it has been verified? (Although I thought this was already done.)
Thanks,
Jeremy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden