0

I am trying to integrate Unit Tests in my current Xcode project using the OCUnit Testing Framework. I have been following Apple's documentation:

http://developer.apple.com/library/mac/#documentation/developertools/Conceptual/UnitTesting/02-Setting_Up_Unit_Tests_in_a_Project/setting_up.html,

regarding setting up Logic Tests. When I switch to my testing scheme and run 'Test' under the 'Product' tab, I am receive two errors:

Error 1: Undefined symbols for architecture i386: "_main", referenced from: start in crt1.o

Error 2: ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've tried cleaning my build and also using application tests but nothing seems to work. The tutorials I've views on Lynda seems not to run into these errors. Adding a target and linking it to my current project seems like all that needs to happen in order to start utilizing Unit Tests within Xcode. What do these errors mean and what do they refer to? All input is appreciated!

andrewRC
  • 61
  • 4
  • I was able to handle to get rid of the first error by adding my 'main.m' file to the Test Target's 'Compile Sources' under the 'Build Phases' section. However, I don't believe this is a very clean solution because I will enviably have to add hundreds of files under the 'Compile Sources' tab in order to make sure I don't receive anymore errors. – andrewRC May 21 '13 at 23:44

1 Answers1

0

1) Create a new iOS project say one view controller type, and specify you want unit tests at creation, now you can see how Xcode has wired it - you will have a reference.

2) create a new project of the type and name as your current one in a temp folder. Move your original project file to another temp folder, move the new one to where original one was, then import all files checking unit test target.

David H
  • 40,852
  • 12
  • 92
  • 138
  • Hi David, thanks for the help, I've actually started doing just that. Ive created a new project, included the Unit Tests, and start the long migration process for all my source files and libraries. That being said, is there anything I should pay special attention to or be aware of in particular? – andrewRC May 22 '13 at 20:31
  • I am currently trying to copy over the build settings and build phases from my old project and setup the dev environment for the new project that includes the Unit Tests. Currently, I've added all the necessary source files under the 'Compile Sources' as well as adding all the appropriate libraries under the 'Link Binary with Libraries', but Im still receiving compilation errors (about 63 in total). Any guidance or suggestions? – andrewRC May 22 '13 at 20:31
  • Update the question with the errors. I don't think you can link in UI based classes, or ones that refer to the UI. In my code I added a special build configuration called "ReleaseForUnitTesting" and defined UNIT_TESTING there, and then ifdef'd blocks of code that I needed to exclude. Or provide stubs, or refactor. This obviously can chew up time. – David H May 22 '13 at 20:45