Kiwi’s Basic Unit Testing

If you want to make just some basic tests, with Kiwi, in your UIViewController‘s IBOutlets and IBActions, you can do something like this:

 __block MyViewController *viewController = nil;
 beforeAll(^{ // Occurs once
 afterAll(^{ // Occurs once
   viewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
   // Lazy loading of the UIView's
   __unused UIView *aView = viewController.view;
   viewController = nil;
 it(@"should not be nil", ^{
   [viewController shouldNotBeNil];
 it(@"should have the IBOutlets not nilled", ^{                            
   // The description's Label IBOutlet
   UILabel *descriptionLabel = (UILabel *)[viewController objectForPropertyName:@"descriptionLabel"];
   [descriptionLabel shouldNotBeNil];

 it(@"should respond to the IBActions", ^{
   // This Button should have an action
   NSNumber *actionMethod = @([viewController respondsToSelector:@selector(anAction:)]);
   [[actionMethod should] beTrue];

Don’t forget that with this you are only able to see that the IBAction exist and the UIViewController responds to it… Not that the your Xib’s element is connect to it.

Tagged , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: