Reputation: 75998
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.
Upvotes: 46
Views: 22259
Reputation: 9077
It's even easier now in Xcode 14.x (14.3.1 in my case).
Upvotes: 0
Reputation: 79
Upvotes: 0
Reputation: 8395
Xcode 4 now have this feature. Simply create a "run scheme" that has the test cases that you want to run.
Upvotes: 51
Reputation: 24689
You can also use xctool
from the commandline with the --only
argument, which will only run the specified testcase(s).
Upvotes: 3
Reputation: 659
⌃+⌥+⌘+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.
Upvotes: 38
Reputation: 42554
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.
Upvotes: 14
Reputation: 925
As you have noted, the OCUnit test framework marks methods whose name start with 'test' as test cases. This is done at runtime
In practice, your test cases should run so fast that it should not matter how many are enabled; your debugger should be able to stop inside your test case very quickly after you press "Debug".
That being said, the quickest way to disable some tests is probably to use an #if 0 / #endif block. The feature to disable test cases dynamically does not exist in Xcode / OCUnit, since there is no GUI component.
In theory it should be doable, because at runtime (and before all tests are run) there are ways to access the test list in OCUnit, but this requires modifications to the OCUnit source code, which is not desirable (it will be wiped out in the next Xcode update, for one).
Finally, if that feature is important to you, you can easily write your own test harness that mostly replicates what OCUnit does. Then you can tweak it to your heart's content, add UI, etc.
It is not difficult, and a little educational. Here's a good link to get you started:
http://gusmueller.com/blog/archives/2009/10/how_to_write_your_own_automated_testing_framework.html
Upvotes: 0