Once in a while, when testing your Objective-C code, you want or have to mock a class method. Or you want to replace the implementation of a class method. The following code replaces the implementation of originalClassMethod of SomeClass with the implementation of mockClassMethod of MockClass:
Some time ago, I wrote about how to use Jenkins for Cocoa/iPhone projects. Back then, I used GHUnit which can produce JUnit test results XML files. Recently, I found OCUnit2JUnit which converts OCUnit results to JUnit result XML format. Thus, no more GHUnit. Do the following
xcodebuild -target NAME_OF_TARGET -configuration Debug clean test | /PATH/TO/ocunit2junit.rb
xcodebuild -scheme NAME_OF_SCHEME -configuration Debug clean test | /PATH/TO/ocunit2junit.rb
Assume, you have an Xcode project Parent and another project Child, which is registered as a subproject of Parent. Let’s further assume that Child is registered as a Git submodule of Parent. Imagine that you want to use Jenkins for continuous integration for the project Parent. Do the following:
Make sure that xcuserdata folder in Parent.xcodeproj is included in the Git repository.
For my small projects Qmind and Qdesktop I needed a Objective-C counterpart of Mockito’s ArgumentCaptor. As far as I can see, OCHamcrest or OCMockito do not offer this functionality. Thus, I wrote an OCHamcrest matcher which does the job: ArgumentCaptor.zip