How to unit tests functions which return results asyncronously in XCode?
Posted
by DevDevDev
on Stack Overflow
See other posts from Stack Overflow
or by DevDevDev
Published on 2009-12-07T22:09:19Z
Indexed on
2010/04/11
18:03 UTC
Read the original article
Hit count: 226
I have something like
- (void)getData:(SomeParameter*)param
{
// Remotely call out for data returned asynchronously
// returns data via a delegate method
}
- (void)handleDataDelegateMethod:(NSData*)data
{
// Handle returned data
}
I want to write a unit test for this, how can I do something better than
NSData* returnedData = nil;
- (void)handleDataDelegateMethod:(NSData*)data
{
returnedData = data;
}
- (void)test
{
[obj getData:param];
while (!returnedData)
{
[NSThread sleep:1];
}
// Make tests on returnedData
}
© Stack Overflow or respective owner