The Xcode Test navigator shows a list of test case classes.
I want to delete a test case class because it's no longer needed.
I've tried many typical approaches, such as pressing delete, or looking for a "-" icon, or "Remove" menu item, or searching for help in Apple Xcode documentation.
I've found this workaround:
In the Project navigator, remove the file from the project and delete the file.
Quit Xcode and re-launch it. The Test navigator seems to lose track of the test classes and test cases, and show zero items.
Run the tests. The Test navigator seems to rebuild the list of test classes and test cases.
If that still doesn't work, try these...
Delete Xcode Derived Data:
Xcode menu -> Preferences -> "Locations" icon -> "Derived Data" section.
Click the tiny gray circle arrow; this opens the Finder and shows the DerviedData folder.
Delete the entire folder.
Rebuild:
Product menu -> Clean.
Product menu -> Build.
Is there a simpler way to accomplish the goal of deleting a test class? Ideally without needing to relaunch Xcode, or rebuild the project, etc.?
Related kind of issue: How can I delete Xcode test cases from the test case view?
I'm using Xcode 6.3 and Swift 1.2, if that helps to know.
Edit: In the comments, @CouchDeveloper points to the official Xcode 6.3 release notes, which describe a known bug # 20373533:
Swift tests are not automatically discovered in this release of Xcode. Test annotations in the source editor sidebar will not appear, and the test navigator and the table of tests in the Test action of the scheme sheet will be empty. ...
The bounty on this question is for any solution or better workaround. Any workaround is fine, such as using the Xcode GUI, or using command-line xcodebuild, or any shell script that kludges the project files.
You can either right click the test and delete or select the target then select the minus symbol ( - ) at the bottom of the Document Navigator pane. Hope this helps.
You can disable XCTests run by Xcode by right clicking on the test symbol in the editor tray on the left. You'll get this menu, and you can select the "Disable " option.
Use the XCTest framework to write unit tests for your Xcode projects that integrate seamlessly with Xcode's testing workflow. Tests assert that certain conditions are satisfied during code execution, and record test failures (with optional messages) if those conditions aren't satisfied.
To add a unit test target to an existing Xcode project, choose File > New > Target. Select your app platform (iOS, macOS, watchOS, tvOS) from the top of the New Target Assistant. Select the Unit Testing Bundle target from the list of targets.
If you want to delete just a single test class, you can click on the file name in the Project Navigator and press Delete and Move to Trash.
If you want to delete then entire Testing bundle, click your project name in the Project Navigator. Then select your Tests target. Click the minus (-) button at the bottom to delete it.
It is a good idea to do Unit Testing (and UI testing) in your projects. So if you want to add them back in then just click the plus (+) button.
See also
Using Xcode 6.2, all I had to do was to switch to the Project navigator, select the file, and press delete. I then clicked the "Remove Reference" button in the confirmation dialog that appears. After that, the tests in that file disappeared from the Test navigator immediately. Adding the file back, the tests reappeared.
I didn't have any need to delete the derived data folder, restart Xcode, etc.
Adding the file to the project again instantly restored the tests in the Test navigator.
This is certainly the desired behavior, and it sounds like it's broken in Xcode 6.3 but possibly fixed again in 6.3.1. So the real answer may just be that you need to upgrade to 6.3.1 (or downgrade to 6.2).
Before:
After:
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