I have a file with unit tests
testOne() {...}
testTwo() {...}
...
but when I am troubleshooting I would like to turn off all except the unit test
that is causing problems (due to massive amount of logging). At the moment I have done like this:
#if 0
testOne() {...}
#endif
..
#if 1
testTroublesome() {...}
#endif
But I was wondering if there is some better more convenient way to do this?
You could for example have an environment variable to signify which test to run, with unset meaning run them all (which would be the usual case). Like so: (this is C, but I think it’ll work in objetive C as well)
and then when running each test
Or you could put the same condition inside the test itself and just return if it fails. This wouldn’t keep your tests from being compiled though, but I don’t think that’s your problem is it? Just set the environment variable to the test you want to run, and none of the others will.
EDIT
To make it even easier, put that in a macro
and always execute your test with that
… and you’ve got yourself a little unit test framework going. Before taking it too far and reinventing too many wheels though, you should (as has been pointed out) perhaps take a look at existing frameworks.