开发者

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

开发者 https://www.devze.com 2023-01-15 11:53 出处:网络
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.

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(helperTestSome开发者_Go百科Test:)
name:connectionFinished
object:nil];
// connect to server
}
- (void) helperTestSomeTest:(NSNotification)notification {
 STAssertWhatever(whathever, nil); // not working
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消