I know it is best practice to run all unit test cases after any change to make sure not breaking anything. However, some times, e.g. debugging, I really want to run only one single test case. It seems Xcode doesn't provide any such feature in UI, while other testing framework such as JUnit has such features.
Is there any workaround to have only one testcase run in Xcode?
P.S. most of my test cases are logic tests. So, they are not run in iPhone device.
With a keyboard shortcutHit ^ ⌥ ⌘ U to run the tests for the cursor's context. If you are inside a test method, like in the example below, the context will be that method. If your cursor is in a test class, but outside a method, the context will be that test calls; all its tests will run.
Run Selected Test Case You can use ⌃⌥⌘U to trigger the test case where your text cursor is currently located. If your text cursor is highlighting an XCTestCase class, then all the test cases within that class will be run.
Test Lab runs unit tests and UI tests using the XCTest framework. To run your app's XCTests on Test Lab devices, build it for testing on a Generic iOS Device: From the device dropdown at the top of your Xcode workspace window, select Generic iOS Device. In the macOS menu bar, select Product > Build For > Testing.
Xcode 4 now have this feature. Simply create a "run scheme" that has the test cases that you want to run.
⌃+⌥+⌘+U
You can also use the keyboard short cut of Control-Option-Command-U
Expert taken from Apple Documentation
Product > Perform Action > Test . This dynamic menu item senses the current test method in which the editing insertion point is positioned when you’re editing a test method and allows you to run that test with a keyboard shortcut. The command’s name adapts to show the test it will run, for instance, Product > Perform Action > Test testAddition. The keyboard shortcut is Control-Option-Command-U.
I'm sure that no one missed the release of Xcode 5 and its ability to easily run a single test case, but adding this answer just for completeness.
In Xcode 5 you can run a single test case by clicking the little play button that you can find next to the test in the test navigator or next to the test method in the editor. In both places it shows up when you hover over it.
You can also use xctool
from the commandline with the --only
argument, which will only run the specified testcase(s).
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