Wednesday, October 20. 2010

When I first started writing unit tests using the OCUnit testing framework, my unit tests were failing when I ran them, but when I set break points to debug them they started passing. It turned out, after much swearing and frustration, that there were errors being spewed to the standard error file handle. This error looked a little something like this:

GC: forcing GC OFF because OBJC_DISABLE_GC is set

Normally this wouldn't be a big deal, and my application at it core relies on reading messages from both standard out and standard error as part of communicating with an NSTask object. I'm using RegexKit in order to parse the output into a meaningful set of data, and that's where the problem manifests itself. Since this error is coming from the unit testing harness and my regex's are not expecting this error message in the standard error file handle, this led to failed unit tests.

Naturally, I immediately started googling for the answer, and read posts every from CocoaBuilder to StackOverflow, and everyone suggested to change the Garbage Collection behavior from Unsupported to either Supported or Required. Easy enough, and so I did, in these steps:

Double click on the project at the top of the project browser

Find the garbage collection setting

Change the value to either supported or required (supported in my case, as I'm actually using the retain count method)

Done and done...or so I thought. I ran my unit test again, and I continued to get the same error message. I switched the garbage collection setting to the other value (required in my case) and still I continued to get the error message.

So, I went back on the hunt for the answer and the same answer came up again and again, "Switch your garbage collection setting", which was not solving my problem. In the end, I did end up solving my problem and the answer is indeed "switch your garbage collection setting" but one thing no one told me, and I'm here to tell everyone having the same problem as I was having, is exactly WHICH garbage collection setting to change.

The secret it turns out is that the Unit Test Bundle has its own garbage collection setting, and its not inherited from the project level setting.

So, instead of double click on the project, double click HERE:

and change that garbage collection setting to either Supported or Required, per normal:

The instant I changed the unit test bundle's setting, the errors in standard out that I'm not expecting are gone.