Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8650215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:45:47+00:00 2026-06-12T13:45:47+00:00

I’ve successfully added a normal Unit Testing Bundle to my project, following these instructions

  • 0

I’ve successfully added a normal Unit Testing Bundle to my project, following these instructions. I can build and run my test target and the one sample test works fine.

Things start to go downhill when I try to test a specific class.

In my App, many of my .h files are included in the .pch file. Also, MyModel interacts with other classes. Because of this, when I import MyModel.h and use it in my test, I get a bunch of errors pertaining to the fact that other files couldn’t be loaded. My workaround to this is to simply add the same files in my test target’s .pch file and also add those files to the test target’s “compile sources” list.

So I add those classes to the test target and to the .pch, try to run, and I just end up in an endless loop, always needing to require more files. When I finally add every .m to my project, running the tests still fails spectacularly.

Any idea how I need to set up my project correctly so that I can just simply #import "MyModel.h" into my test file and write/run my tests? Is it possible that my project is configured in a way that will make testing impossible?

Update 1
Followed Carl’s suggestions but can’t get past step 2. I get:

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_MyModel", referenced from:
      objc-class-ref in BaseUnitTests.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

It’s at this point where I would then add MyModel.m to “Build Phases/Compile Sources” and go down the endless path of adding every other .m file to the test target’s “Compile Sources”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:45:48+00:00Added an answer on June 12, 2026 at 1:45 pm

    Code can definitely be written in ways that make testing difficult, especially when it wasn’t written with testing in mind. But it’s not impossible. Right now you just need to clean up your imports. I think the approach I’d take is

    1) Remove all your non-test-case class implementations (.m) from the tests target – they don’t need to be there. Do this by removing them from the “compile sources” pane in the test target’s build phases.

    2) Copy all your PCH imports into your test case (temporarily). Import "MyModel.h". Try to just get an instance of MyModel and test it isn’t nil and has the right class. Just keep adding imports if you need to but don’t add .m’s.

    3) This and the next step are optional but I highly recommend them, as they might reveal trouble areas in your code that will prevent you from writing fine-grained tests. Once you get that simple test passing, it’s time to start cleaning up your imports. Switch back to your main project. First things first, I’d start removing any of your own classes from the pch (not counting library / framework type imports). Remove headers from the pch one at a time, and import them in the files that truly need them.

    3a) As you’re going through this process make sure you import as few files from other header files as possible. You should only have a #import in your .h in a few situations, generally: 1) Subclassing a class declared in the imported file 2) Implementing a protocol declared in the imported file 3) referring to any C type defined in the imported file. For protocols and classes, forward-declare them with @protocol and @class in the header and only import them where you actually message them or access their properties (usually in your .m)

    So, at this point, you should have a single passing unit test and a cleaner pch. Make sure to clean up the imports in your unit test now. Switch back to your testing target, and start writing more tests. As you make your interfaces more focused and testable, the need to import files will decrease. Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.