I've got an iOS app with some application tests in which I use OCMock. Depending on which simulator device and OS I run them on they either all pass, or I get weird exceptions and crashes. I believe this is happening because when using an application test the test bundle is running in the test host--my real app, which is doing stuff its normal operations. Occasionally it encounters a singleton I've mocked (like +[NSUserDefaults standardUserDefaults]) and then fireworks happen when the app tries to call unexpected methods on the mock.
Does anyone have a strategy for dealing with this problem in application tests? Or do you exclusively use OCMock in logic tests? I've been trying to track down a way to detect if application tests are being run and then suspend activity in my app which might conflict with what I'm testing... but so far haven't dug up anything to help detect when these tests are running.
I've tried checking [NSBundle allBundles] in application:didFinishLaunchingWithOptions:, but it only lists the main app bundle. I've also tried looking for a TEST_HOST environment variable, but getenv() returns NULL for that.