How to get started with unit testing in Xcode 4?

2020-07-10 09:56发布

问题:

Does anyone know how to get started with unit testing in Xcode 4?

How do I create a test and how do I run it?

EDIT: All the Apple documentation is for Xcode 3

回答1:

See this question: Unit testing in XCode 4

Basically, it says to use GHUnit and ignore SenTestingKit for now (bceause it's broken). GHUnit is pretty nifty.



回答2:

Although most of the documentation is in fact for XCode 3, the XCode4 User Guide: Building and Running Your Code gives clear step-by-step instructions. Essentially, you create a Cocoa [Touch] Unit Testing Bundle target and add all your test code to that target. Then add the target to your build scheme. Pretty straightforward (not something I'd say for XCode4 in general...)

I just switched from using GTM (which is what GHUnit uses) and it works fine. The main thing you get from GHUnit is the nifty UI which shows you all the tests and whether they succeeded. The other problems mentioned with OCUnit (such as no debugging) are no longer relevant.



回答3:

I used to say GHUnit, but for XCode 4 specifically I say OCUnit. See my comparison blog post.