Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Unit Tests that run on device to Existing Xcode 4 Project

I'm trying to add unit tests to an existing universal app in Xcode 4. I've followed the tutorials and while the logic tests run fine in the simulator, when I try to test on device I get a dialog saying "Logic Testing on iOS devices is not supported. You can run logic tests on the Simulator." However, I've noticed that when you create a new project in Xcode 4 and check the Include Unit Tests box, it will actually install and run the tests on device. Am I missing an option somewhere that would allow me enable that on my existing project?

like image 436
Jose Ibanez Avatar asked Apr 13 '11 15:04

Jose Ibanez


People also ask

How do I add unit tests to an existing Xcode project?

To add a unit test target to an existing Xcode project, choose File > New > Target. Select your app platform (iOS, macOS, watchOS, tvOS) from the top of the New Target Assistant. Select the Unit Testing Bundle target from the list of targets.

What is difference between unit tests and UI test in Xcode?

Generally speaking, an Xcode Unit Test exercises and evaluates your Swift code, but does not inspect the impact is has on the User Interface, while an Xcode UI Test evaluates the UI behavior in response to actions, but does not inspect your code. As always, these are generalized statements that have exceptions.

How do I run unit test cases in Xcode?

⌘U will build and run all your test cases. It is the most commonly used shortcut when creating unit test cases. It is equivalent to ⌘R (build & run) while doing app development. You can use this shortcut to build your test target and run all the test cases in your test target.

Where should the unit tests reside in the repository in Devops?

Unit testing often finds its place just after the build stage of the delivery pipeline. Developers commit their code and push it to a code repository. This triggers a build. Once the build is complete, unit tests run on the compiled code to ensure the new code hasn't broken the old code.


1 Answers

I think I figured it out by going line by line through the Build Settings for the Cocoa Touch Unit Testing Bundle.

Build Settings

Linker

  • Set Bundle Loader to $(BUILT_PRODUCTS_DIR)/[Your App Name].app/[YourAppName]

Unit Testing

  • Set Test Host to $(BUNDLE_LOADER)

Build Phases

Add the application target to the Target Dependencies.

Once you do all that, you can just hook up your device and hit Test.

like image 195
Jose Ibanez Avatar answered Sep 20 '22 12:09

Jose Ibanez