Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test for NSLog output

Tags:

xcode

xctest

I'm writing a framework that also includes a simple logger that can be enabled/disabled at runtime. Since I want have unit tests for as much of the framework as possible, I also want to test whether the logger works correctly.

The logger simply logs via NSLog. Now I need to test whether the output really matches the expectation (i.e. does it really log and is the output in the correct format). I couldn't find a way to do that using Xcode's XCTest framework.

I could modify the logger so that it doesn't use NSLog while testing but that strikes me as error-prone. So, is there a better way to check the NSLog output?

like image 937
DarkDust Avatar asked Feb 05 '16 11:02

DarkDust


1 Answers

Have the logger output strings. Have another object print these. This way you can unit test the first object separately from the second.

like image 112
Joride Avatar answered Nov 20 '22 03:11

Joride