I use unit test. Also I use asynchronous requests for retrive data from server. My questions is how can I test this request, cause now my tests work without waiting retriving data.
I using ASIHTTPRequest for get data from the server. There is how I check my request
- (void)testSignIn {
self.request = [[Requests alloc] init];
[self.request signInWithEmail:@"[email protected]" andPassword:@"123456"];
}
Here I have a problem. If in this method I will insert STFail befaore I get response it will complete with error in each time (because retrive data will take it some time and this is not a synchronize reuest)
How to resolve this problem?
If you really want to test network code in a unit test: Switch to using GHUnit, which actually contains support for waiting for asynchronous events.
But really, you shouldn't be doing this. In the above test, what are you testing? Your backend service or your Requests class?
Strictly speaking, Unit Tests should test a unit of code not being going off to the network to retrieve data.
If possible, restructure your tests to provide static test data that will test your functions. You want your tests to be as reliable and consistent as possible. By introducing the network, you are setting yourself up for inconsistent tests (when the network is down, or slow), which may lead to your tests being disabled (assuming you're working in a team)