0

I am using KIWI for testing my iOS app. I would like to ask how to check if element exists in UIViewController, however, I declared the element inside the implementation file and not in header file.

Is that possible?

#import "Kiwi.h"

SPEC_BEGIN(HomeViewController)
    describe(@"HomeViewController", ^{

        context(@"when instantiated", ^{
            __block HomeViewController *controller = nil;

            beforeEach(^{
                controller = [[HomeViewController alloc] init];
            });

            it(@"it should have been instantiated", ^{
                [controller shouldNotBeNil];
            });

            it(@"it should have UITableViewController", ^{
                /*
                    WHAT TO DO HERE
                 */
            })
        });
    });

SPEC_END
dr.calix
  • 667
  • 8
  • 21

1 Answers1

0

Basically, you want to check if a certain UI element appears on the screen.

Firstly, this is not what unit testing is best suited for, unit tests should check if certain pieces of code behave as expected under as many as possible combinations of inputs.

Secondly, you can make some arrangements if you really want to test this, like adding a HomeViewController+Internal.h header where you place the "private" member. Or, if the table view controller is declared as a property, you can ask the generated getter for the property (e.g.: [controller usersTableViewController] if the property name is usersTableViewController)

Thirdly, keep in mind that tests like this tend to make it hard to refactor your application code, as refactoring the code will likely lead to refactoring the affected unit tests, which might not be fun and is error prone.

Cristik
  • 30,989
  • 25
  • 91
  • 127