Search code examples
unit-testingxcode4

Xcode 4: Application Tests in iOS Simulator


I am confused about Xcode4's capability to run Application Tests in iOS Simulator.

On the one hand, Apple's own documentation says that application tests can be run in simulators. On the other, I have read through the forums here and it seems as though most folks have found otherwise, that Application Tests can only be run on a device.

If the latter is true, please include a link to document this. I haven't been able to find anything.

Anyways, from iOS App Development Workflow Guide:Unit Testing Applications:

Listing 6-2 Transcript of an iOS Simulator-based application unit-test run

and also

Note: Although Xcode can run logic and application unit tests in simulators, Xcode cannot run logic unit tests on devices. Therefore, if you include and have active both types of unit tests in a scheme, you will not be able to use that scheme to run unit tests on devices.

The problem is that the Simulator does not provide access to the UIApplicationDelegate. Here is a sample test to demonstrate:

- (void) testAppDelegate { id yourApplicationDelegate = [[UIApplication sharedApplication] delegate]; STAssertNotNil(yourApplicationDelegate, @"UIApplication failed to find the AppDelegate"); }

This test fails in my project. BTW my Logic Tests run fine.


Solution

  • My bad, I spoke too soon. I have tried this solution and it works. In other words, I am now able to run both Logic Tests and Application Tests from within iOS Simulator.

    Be sure to set both bundle loader AND test host parameters in the Build Settings for your test targets.