title: Objective C - Unit Testing & Mocking Objects?
body: <p>How do you unit test Objective C code? (iPhone)</p>
  
  <p>In other languages such as java and .Net you can use Dependency Injection, to be able to unit test and pass mocked object in your current code.
  However, I could not find a reliable dependency injection framework for objective c.</p>
  
  <p>Let's say you want to write a unit test for the code below, how can you mock MyObject?</p>
  
  <pre><code>- (void) methodToBeTested
  {
       NSString str = @"myString";
       MyObject object = [[MyObject alloc] init];
       [object setString:str];
       [object doStuff];
       [object release];
  }
  </code></pre>
  
  <p>This is how I would do it with dependency injection. Is there a similar way to achieve this on objective c?</p>
  
  <pre><code>@Inject MyObject object;
  
  public void methodToBeTested()
  {
       String str = "myString";
       // object is automatically instantiated (Dependency Injection)
       object.setString(str);
       object.doStuff();
  }
  </code></pre>