I want to use OCUnit to test my work. but one of my methodes is like this:
- (BOOL)testThread
{
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(thread) object:nil];
[thread start];
return YES;
}
- (void)thread
{
NSLog(@"thread**********************");
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(thread2) object:nil];
[thread start];
}
- (void)thread2
{
NSLog(@"thread2**********************");
}
Now I want to run the test:
- (void)testExample
{
testNSThread *_testNSThread = [[testNSThread alloc] init];
STAssertTrue([_testNSThread testThread], @"test");
}
in my test case but the thread2 dose not run so,what should I do? 3Q!
You can use
dispatch_semaphoreto maketestThreadwait untilthread2has completed: