Useful Xcode shortcuts for unit testing
Table of Contents
Testing is a process we do along with our development. Knowing shortcuts would help you save some time, which will add up in the long run.
Run all tests
Menu Product > Test
or ⌘ - command + U
This command will run all tests in the current scheme.
Use case
Use it when you want to run all of your tests. This is the easiest to remember, and I use this all the time.
You can easily support sarunw.com by checking out this sponsor.
AI Grammar: Correct grammar, spell check, check punctuation, and parphrase.
Run a single test(s)
// Where testName is a test that our cursor poiting
Menu Product > Perform Action > Run <testName>
or ⌃ – control + ⌥ – option + ⌘ - command + U
This command runs a test case where your cursor is currently located.
If your cursor is on an XCTestCase class name or outside a test case, but within the scope of XCTestCase class, then all the test cases within that class will be run.
This shortcut is the same as running the test by click on the indicator next to each test method name.
Use case
I normally use this when I add a new test case. At the time, I finish writing my case, my cursor usually within a scope of the case. No need to move my cursor to that little indicator.
Rerun Previous Test(s)
Menu Product > Perform Action > Run <testName> Again
or ⌃ – control + ⌥ – option + ⌘ - command + G
This is a very handy command. It reruns the last test method executed.
Use case
I use this when debugging my failed test case. You can edit your code and use this shortcut to run the last test without going back to your test case.
Build for test
Menu Product > Build for > Testing
or ⇧ - SHIFT + ⌘ - command + U
This command will build the test bundle products without running the tests.
Use case
When develop a new feature. Building ⌘ - command + B and Runing ⌘ - command + R won't build your test bundle, so at the time you finish your feature, a lot of your tests might not even compile.
This command is useful when changing code to check for warnings and compile errors of your tests. The sooner you know the error, the easier to fix. I try to run this along with build command (but I always forgot the shortcut).
You can easily support sarunw.com by checking out this sponsor.
AI Grammar: Correct grammar, spell check, check punctuation, and parphrase.
Related Resources
Read more article about Xcode, Testing, Workflow, or see all available topic
Enjoy the read?
If you enjoy this article, you can subscribe to the weekly newsletter.
Every Friday, you'll get a quick recap of all articles and tips posted on this site. No strings attached. Unsubscribe anytime.
Feel free to follow me on Twitter and ask your questions related to this post. Thanks for reading and see you next time.
If you enjoy my writing, please check out my Patreon https://www.patreon.com/sarunw and become my supporter. Sharing the article is also greatly appreciated.
Become a patron Buy me a coffee Tweet ShareHow to remove text from a navigation bar back button
There are a lot of hacky ways to modify or remove a back button title. This tip will show you how to do it properly.