ios - How to create unit test if result is logging with NSLog -


I want to make unit testing that checks a particular case. The result of this case is the result of system code NSLog < / Code>.

  & lt; 2014-02-19 03: 05: 11 & gt; Warning bla-bla-bla Please check the code.  

I searched a lot, but have not found a decent solution. Is there any chance that logging operations can be captured by observation or MB Exode console content?

Any advice will be useful!

Edit OK, I think I have some misgivings that I want to test. The library wants to warn the developer, who uses it, about some incorrect input. It will continue to process them anyway and will give results (MB incorrect result). But at some point of processing I check the value (although not the initial value) and the log alert message and then, the process is continuing. Even if I define this argument then I do not want to make this functionality public

I have only one case, so what you can do is 1. Direct your log in a txt file.

+ (zero) record log {NSArray * allPaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); NSString * Document Directory = [allPaths ObjectOut Index: 0]; PathForLog = [document directory stringbapping path comparison: @ "FB LogTest Test"]; NSLog (@ "path =% @", Pathforg); StderrSave = dup (STDERR_FILENO); Freeopen ([pathfornog cStringUsingEncoding: NSASCIIStringEncoding], "a +", stderr); }

2. Find the string "bla-bla-bla" pattern in the .txt file. And use XCTTest to test when the string is found.

3. Close the file and delete it so that other NSLogs will return to the console.

  + (zero) close log {fflush (stderr); Dup2 (stderrSave, STDERR_FILENO); Close (stderrSave); NSFileManager * fileManager = [NSFileManager defaultManager]; NSError * Error = Zero; [Remove file manageright path: pathflow error: & amp; Error]; }  

I wrap it in my custom test class so that I can use it with other standard XCTTest

.

Comments