Search code examples
objective-cunit-testingxcodensnotifications

Should I test a model class which sync often to the server?


And how do I do it, since obviously there are a lot of async methods, and no way (that I know of) to check them in a unit test.

For example:


- (void) testSomeTest {
// things
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(helperTestSomeTest:)
name:connectionFinished
object:nil];
// connect to server
}
- (void) helperTestSomeTest:(NSNotification)notification {
 STAssertWhatever(whathever, nil); // not working
}


Solution

  • You have a variety of solutions to Unit test this. Mock objects, Stubs, and Fakes all come to mind.

    They seem similar, but this is a great look at the differences.

    By the way, to directly answer your question-line: Yes, test 100% of the code. Everything.