7

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

TheLearner
  • 19,387
  • 35
  • 95
  • 163

3 Answers3

4

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.

Community
  • 1
  • 1
occulus
  • 16,959
  • 6
  • 53
  • 76
  • The installation instructions make no sense at all e.g.: In the Finder, copy GHUnit.framework to your project directory (maybe in MyProject/Frameworks/.) – TheLearner Mar 22 '11 at 10:23
  • Try http://stackoverflow.com/questions/1675307/best-way-to-install-a-custom-cocoa-framework perhaps – occulus Mar 22 '11 at 11:20
  • @TheLearner That instruction just means copy the .framework somewhere into your project, e.g. a new folder in your project for frameworks called "Framework". – occulus Mar 22 '11 at 11:24
4

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.

  • +1 i am using ocunit as well in xcode4 and it works quite well part from some issue with break points not matching actual lines. Anyway a big leap forward from xcode3. – AndersK Apr 06 '11 at 06:28
2

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

makdad
  • 6,402
  • 3
  • 31
  • 56