I have the same case , so what you can do is 1.Direct your log to a txt file.
+ (void)recordLog{
NSArray *allPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [allPaths objectAtIndex:0];
pathForLog = [documentsDirectory stringByAppendingPathComponent:@"FWTestLog.txt"];
NSLog(@"path = %@",pathForLog);
stderrSave = dup(STDERR_FILENO);
freopen([pathForLog cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
}
2.Search a the string "bla-bla-bla" pattern in the txt file.And use XCTTest to test if the string is found.
3.Close the file and delete it so the other nslog will go back to console.
+ (void)closeLog{
fflush(stderr);
dup2(stderrSave,STDERR_FILENO);
close(stderrSave);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = nil;
[fileManager removeItemAtPath:pathForLog error:&error];
}
I wrap it inside my custom test class so that I can use it with other standard XCTTest