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

  • Home
  • SEARCH
  • 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 8773999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:27:03+00:00 2026-06-13T18:27:03+00:00

I have finally started to test my code while developing iOS applications. However, I

  • 0

I have finally started to test my code while developing iOS applications. However, I am curious to hear more about how others are creating testable code, especially when it comes to injection of fake objects into the class under test. So far this is how I do it:

// 1) Init CUT with fakes (constructor injection)
A *a = [[A alloc] initWithB:C:D:…..];

// 2) Expose dependencies as properties (property injection)
a.B = myB;

I prefer 1) since I don’t like to expose any internal data as properties unless I really need to.

My questions is: Are there any alternatives/better/more efficient ways to do property injection when dealing with objective-c and iOS test frameworks?

  • 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-13T18:27:04+00:00Added an answer on June 13, 2026 at 6:27 pm

    It has now been a while and I have had the opportunity to work with different solutions since I asked the question. I now, in most cases, prefer a combination. If a class A is dependent on class B, I would init a with an instance of B, as such:

    A* myA = [[A alloc] initWithB:myB];
    

    In addition to this, I would expose B as a property so that it can be switched at runtime. In some cases an interface pattern would even be preferable.

    - (id)initWithBy:(id<bProtocol>)aB;
    

    This obviously doesn’t suit all situations, but I have found it a good way of injecting dependencies into my classes and thereby making them more testable.

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

Sidebar

Related Questions

I have finally started messing around with creating some apps that work with RESTful
I have finally got in my mind what worried me about Dependency Injection and
I started finally to understand Apache mod_rewrite. It's pretty GREAT! Plz have a look
I have finally started to take the time out to grok the continuous integration
I have started working with a large code base, and a lot of the
I've finally started to learn PHP and I quite have trouble with it. I
I have just started using EF Code First to implement a simple blog. I
I have finally started upgrading my Rails apps from 2.3.8 to 3.1.0. I was
I have recently started working with backbone.js and i am finally started to get
I recently (finally?) started to use .format() and have a perhaps a bit obscure

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.