Which is testing framework is best?
This really depends on which day you ask me that. I’ve been working with Expecta on XCTest recently, and I like that combination, but there are things that the other frameworks appear to do better. Here’s a comparison of some key features:
|Framework||Xcode Integration||Runs On:||Debugging||Notes|
|XCTest||Best||Both||Good||Built-into Xcode 5|
|GHUnit||Add-on||Both||Good||Separate build target|
|Expecta||Good||Both||Good||Matchers, supports async|
|Kiwi||Good||Simulator||Difficult?||Blocks run on OCUnit|
Note that GHUnit runs as a separate build target. This allows running unit tests stand-alone on either a device or simulator. This is fabulous for things like API tests. Not quite so convenient for Continuous Integration tests.
Apple often breaks OCUnit or its templates when a new version of Xcode is released. Caveat Emptor.
How much test coverage is enough?
As much as you can. Programmer’s often panic when asked to provide 100%, so instead I just say “test everything”.
Should I unit test views and/or view controllers?
You should test every line of code that you write. If you are inheriting legacy code, then add tests for every line of code that you plan to modify. Note: Michael Feathers defines legacy code as code that doesn’t contain tests. I agree.
Doesn’t adding unit tests take more time?
That depends on which times you are comparing. If you compare the sum of the times spent writing the code, debugging the code, and later on extending the code, then unit tests should be the hands-down winner. If you are only comparing the time spent writing the code, then clearly it takes less time to write buggy, unmaintainable code that might not work correctly.