You are currently viewing 5 Must-Know Xcode Shortcuts for Unit Testing

5 Must-Know Xcode Shortcuts for Unit Testing

Writing unit tests is a major part of the app development lifecycle. Xcode has some pretty useful built-in unit testing shortcuts, however, a lot of developers are not aware of their existence.

In this article, I will show you 5 unit testing shortcuts where you can leverage to improve your productivity while creating unit test cases or performing TDD.


Knowing the Mac Keyboard Symbols

Before we get started, here’s a quick revision of the Mac keyboard symbols.

The Mac keyboard symbols
The Mac keyboard symbols

With all that in mind, let’s check out the 5 must-know shortcuts for unit testing.


Build and Run All Test Cases

⌘U (command + U)

⌘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.


Build the Test Target

⇧⌘U (shift + command + U)

Hitting ⇧⌘U will trigger a build on the test target, note that this shortcut will not run your test cases.

Often you will use this shortcut to check for compile errors when creating unit test cases. It is equivalent to ⌘B (build only) while doing app development.


Run All the Test Cases

⌃⌘U (control + command + U)

Using ⌃⌘U will run all the test cases without building the test target. It is the opposite of ⇧⌘U.

This is especially useful when you want to skip a slow-building test target and jump straight into running all the test cases.


Run Previous Test Case(s)

⌃⌥⌘G (control + option + command + G)

You can use ⌃⌥⌘G to trigger your previously run test case. It is extremely useful when you are doing bug fixing because you can hit this shortcut to run the same test case again and again.

Do note that if your last test action is running the entire XCTestCase class, then hitting this shortcut will run the entire class again.


Run Selected Test Case

⌃⌥⌘U (control + option + command + U)

You can use ⌃⌥⌘U to trigger the test case where your text cursor is currently located.

Shortcut to run selected test case in Xcode
Run the selected test case

If your text cursor is highlighting an XCTestCase class, then all the test cases within that class will be run.

Shortcut to run selected XCTestCase class in Xcode
Run all test cases within the selected XCTestCase class

Wrapping Up

It doesn’t matter if you are just fixing a minor bug or performing TDD on your next big app, able to leverage these 5 shortcuts efficiently can absolutely increase your daily productivity.

Here’s a summary of the 5 must-know Xcode shortcuts for unit testing.

ShortcutAction
⌘UBuild and Run All Test Cases
⇧⌘UBuild the Test Target (without running any test cases)
⌃⌘URun All the Test Cases (without building the test target)
⌃⌥⌘GRun Previous Test Case(s)
⌃⌥⌘URun Selected Test Case

Feel free to bookmark this article so that next time when you are working on any unit test related task, give these shortcuts a try, I am sure you will like it.


Further Readings

If you like this article, feel free to check out my other articles related to Xcode shortcuts such as:

🔗 Top 10 Most Useful Xcode Shortcuts for Navigation

🔗 Re-enabling the iOS Simulator Slow Animations Shortcut

Furthermore, you can also check out my other articles related to unit testing.


What do you think about these 5 shortcuts? Let me know in the comment section below. If you like this article, feel free to share it.

You can follow me on Twitter for more articles related to iOS development.

Thanks for reading and happy unit testing. 🧑🏻‍💻


👋🏻 Hey!

While you’re still here, why not check out some of my favorite Mac tools on Setapp? They will definitely help improve your day-to-day productivity. Additionally, doing so will also help support my work.

  • Bartender: Superpower your menu bar and take full control over your menu bar items.
  • CleanShot X: The best screen capture app I’ve ever used.
  • PixelSnap: Measure on-screen elements with ease and precision.
  • iStat Menus: Track CPU, GPU, sensors, and more, all in one convenient tool.