I’m currently using GHUnit and OCMock for testing my app. I’m using them because I like the fact that I can run test code on the actual device.
The way my app is currently designed is that I have some central services and objects available through properties on the app delegate. For example, I’ve centralised some core data functionality which can be accessed by [UIApplication sharedApplication].coreData.
The problem I’ve encountered is that in order to run unit tests on the device or simulator, GHUnit uses it’s own app delegate which doesn’t have these properties. So if a unit triggers code which wants to access them, it fails.
So I’m looking at the design of the app and wondering if I should redesign the way these core facilities are made available. How do you guys design your apps?
One thing I’m considering is extracting this functionality out to a separate object so that I can then use OCMock to simulate it for testing purposes.
Any thoughts?
After thinking about this a while I realised there was a simpler solution. I created a category with the app delegate’s interface which applies to the GU Unit app delegate used when running the tests. This way I can get the tests to run and use this category to return OC Mocks when necessary.