Unit Testing Example with OCUnit

Update: I’ve improved on this answer in two ways: it’s now a screencast, and I switched from property injection to constructor injection. See How to Get Started with Objective-C TDD The tricky part is that the method has a dependency on an external object, NSUserDefaults. We don’t want to use NSUserDefaults directly. Instead, we need … Read more

OCUnit & NSBundle

Found only one solution for this problem. When I build my unit-tests, the main bundle’s path is not equal to my project’s bundle (created .app file). Moreover, it’s not equal to LogicTests bundle (created LogicTests.octest file). Main bundle for unit-tests is something like /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.3.sdk/Developer/usr/bin. And that’s why program can’t find necessary resources. And the final … Read more

Unit Testing of private methods in Xcode

Remember that there’s actually no such thing as “private methods” in Objective-C, and it’s not just because it’s a dynamic language. By design, Objective-C has visibility modifiers for ivars, but not for methods — it’s not by accident that you can call any method you like. @Peter‘s suggestion is a great one. To complement his … Read more