I'd strongly suggest you rethink how you are building out this implementation. For starters, a view controllers is great at managing a view, but managing your model data is not what it's for. Its good for passing around your model data to the views it manages, so with that in mind, let's build this out like that.
Let's start by introducing a new class, called FeedController
. This controller's job is to sit between your VC and your model data backing this screen. Let's assume this public interface:
@interface FeedController : NSObject
- (instancetype)initWithFeedArray:(NSArray *)array;
- (NSString *)firstNameAtIndexPath:(NSIndexPath *)path;
- (NSString *)lastNameAtIndexPath:(NSIndexPath *)path;
- (NSString *)fullNameAtIndexPath:(NSIndexPath *)path;
// This should probably have a better name
- (NSString *)textAtIndexPath:(NSIndexPath *)path;
@end
I'm not going to implement these methods, but they'd look exactly like you'd expect. The initializer would copy the array passed into it, store it in an ivar, and the other methods would take the piece of info out of the array at the specific index and apply any custom transformations you must (like combining the first and last name to get the full name). The main goal here is to transfer the data, not manipulate it. The moment you try and manipulate this data in your view controller, is the moment you'll be back to square one, testing wise.
The object of your configureCell:forIndexPath:
is now just to transfer data from the FeedController
class, which is infinitely simple to test. No need to set up a responder chain, mock out objects, or anything. Just supply some fixture data and away you go.
You are still testing the pieces that make up your configureCell:forIndexPath:
but not directly testing that method anymore. If you want to make sure that the view is being populated correctly, great, you should. However, you'll do this differently, this isn't a job for unit tests. Pull out UIAutomation or your favourite UI testing framework, and test your UI. Use the unit tests on the FeedController
to test your data and transformations.
I hope this helps.