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?
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.
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.
⌘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.
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.
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
$(BUILT_PRODUCTS_DIR)/[Your App Name].app/[YourAppName]
Unit Testing
$(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With