Skip to content

Add Test Running Code to the Target

Jeffrey Wear edited this page May 2, 2014 · 7 revisions

By this point, you should have created an Integration Tests target and added Subliminal to that target. Finally, you'll need to add some code to your app delegate to tell Subliminal to begin running your tests. First build your Integration Tests scheme, so that Xcode can provide autocompletion results as you modify your app delegate. Then, import the Subliminal header at the top of your app delegate's implementation file:

#if INTEGRATION_TESTING
#import <Subliminal/Subliminal.h>
#endif

and tell the shared test controller to run all tests (Subliminal will automatically find these tests):

#if INTEGRATION_TESTING
[[SLTestController sharedTestController] runTests:[SLTest allTests] withCompletionBlock:nil];
#endif

This code is conditionalized by the INTEGRATION_TESTING preprocessor macro (set by Integration Tests.xcconfig), and so will not be built into your main application target. This helps you keep straight exactly when you expect the tests to be run: when you run the Integration Tests target, not every time you launch your application.

You don't have any tests written at this point, but you can check that Subliminal is working. Choose Product > Profile (or press ⌘+I) to launch Instruments. Choose the User templates from the sidebar, then choose Subliminal and click Profile.

If everything is set up correctly, Instruments will just log a message that there are no tests to run.

Next: Writing Tests

With everything set up, you're now ready to write some tests.