4.7.2.4 Add hook into the AUT

Finally, the app needs a hook so that it actually allows the attachment and running of the tests when executing the Tests target. This is achieved by using the RUN_FUNCTIONAL_TESTS macro that was defined in the preceding section. This "preprocessor macro" is only defined in the testing target, so the remote controlling won't be possible in the regular target. To allow your AUT to be remote controlled, add the following code to your application delegate:

...
#if RUN_FUNCTIONAL_TESTS
#import "UIRemoteControl.h"
#endif
...

and the following code to the end of its - (void)applicationDidFinishLaunching[withOptions]: method

...
#if RUN_FUNCTIONAL_TESTS
    [UIRemoteControl attach];
    // alternatively you can
    // allow the UIRemoteControl 
    // to use a specific port number 
    // on the iOS device 
    // by using:
    // 
    // [UIRemoteControl attach:<portNo>];
    // 
    // this is necessary
    // e.g. when you're running 
    // different AUTs in parallel on 
    // the same iOS device
#endif
...

You also have to make sure that your application delegate provides a UIWindow property called window which contains the window used to present the app's visual content on the device's main screen.

...
#if RUN_FUNCTIONAL_TESTS
    @property(nonatomic, retain) 
    UIWindow *window
#endif
...

Everything should now be configured. When you run the AUT tests target it will launch your app and allow the ITE to remotely attach (on the port specified, or on 11022 if none is entered) and execute tests.

\includegraphics[height=2cm]{danger} If you do not follow the above steps, the AUT Agent will not be able to communicate with your AUT !

This documentation is derived from the KIF installation documentation (http://github.com/square/KIF) as we make use of KIF internally.



Copyright BREDEX GmbH 2014. Made available under the Eclipse Public License v1.0.