You can run XCTest (unit tests for your Xcode project) easily with 'Run Test' ('Product'>'Test' or
Command+U) on Xcode. This is useful if you make extensive changes to your product code and want to test them all at once because 'Run Test' executes all the test cases implemented in your project.
But there are times when you want to run individual test cases, such as while fixing bugs for a specific method and want to run only test cases for the method.
Select 'Product' > 'Scheme' > 'Edit Scheme' > 'Test' pane > 'Info' tab, and then check and uncheck test case names. By doing this, you can specify which test cases are executed with 'Run Test'. This method is more troublesome as you implement more test cases...
Control + Option + Command + U
This executes a test case in which your cursor is.
Control + Option + Command + G
This re-runs the last test cases executed.
You may find value in specifying test cases with command line interface, if you have many test cases and want to switch execution targets frequently. xcodebuild is one of the command line tools bundled with Xcode.
> xcodebuild test \ > -workspace MyXCWorkSpace \ > -scheme MyAppScheme \ > -destination "platform=iOS,name=my_iphonex" \ > -only-testing:MyXCTargetForTest/MyTestSuite/MyTestMethod
Xcode Version: 9.2
Is there a keyboard shortcut in Xcode 6 to run a single current test function under cursor?
Running individual XCTest (UI, Unit) test cases for iOS apps from the command line
How to use xcodebuild with -only-testing and -skip-testing flag?