开发者

Test Driven Development (TDD): Writing unit tests in Xcode 4

开发者 https://www.devze.com 2023-02-12 18:49 出处:网络
I am keen to write a library project with tests, even if I th开发者_StackOverflow中文版en include the code in other projects (as opposed to linking to the lib.) for inclusion on ios projects.

I am keen to write a library project with tests, even if I th开发者_StackOverflow中文版en include the code in other projects (as opposed to linking to the lib.) for inclusion on ios projects.

It seems checking the 'Include unit tests' isn't enough for xcode 4 to properly initialise a project with tests, and after looking through the Apple documentation I can't find anything relevant.

Does anybody know of any resources or tutorials for getting this working?

Even with the default Cocoa Touch Static Library project, upon choosing "Test" from the "Product" menu, it fails (when linking) with this error (the project is called test1):

library not found for -ltest1
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1

Any help would be much appreciated.


OK I finally got this working.

The trick was to create the library without checking the 'Include unit tests' option in XCode 4. Then I created a new target myself.

(in xcode 4)

  1. Create a new Cocoa Touch Static Library project and DON'T check "Include Unit Tests"
  2. Select the project in the navigator
  3. Go into the "Build Phases" tab
  4. Click 'Add Target' and choose 'Cocoa Touch Unit Testing Bundle'
  5. Go through the wizard until the target is created
  6. Then go in the "Product" menu and choose "Edit Scheme..."
  7. Make sure your project (not the test target) is selected and, select "Test"
  8. Click + to add a new target
  9. Choose your test project and click Add
  10. Now press Cmd+U (this is the shortcut for "Product > Test" menu item) and you'll notice the default test fails.

I hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消