16

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:

  1. In the Project navigator, remove the file from the project and delete the file.

  2. Quit Xcode and re-launch it. The Test navigator seems to lose track of the test classes and test cases, and show zero items.

  3. 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:

  1. Xcode menu -> Preferences -> "Locations" icon -> "Derived Data" section.

  2. Click the tiny gray circle arrow; this opens the Finder and shows the DerviedData folder.

  3. Delete the entire folder.

Rebuild:

  1. Product menu -> Clean.

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

Community
  • 1
  • 1
joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119
  • 1
    You are lucky. Xcode 6.3 doesn't even show my Swift Test cases in the Test Navigator. Other features related to Unit Tests do not work correctly, too. Running the tests may crash Xcode, then relaunching Xcode hangs, ... , etc. etc, ;) – CouchDeveloper Apr 14 '15 at 20:04
  • Ha! Can you do me a favor and upvote this so it gets more views by developers? What they answer may help you too. I'll be adding a bounty when the site lets me. – joelparkerhenderson Apr 15 '15 at 13:42
  • These are known bugs in 6.3, you can read the [release notes](https://developer.apple.com/library/ios/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html) in section **Testing**. And since we are at it, debugging is awful: inspection of variables quite frequently not possible, "next step" jumps backwards and forwards and oftentimes halts in disassembly code, ... – CouchDeveloper Apr 15 '15 at 18:01
  • Thanks for the release notes info; I'm adding that to the question info in case it helps other people here. – joelparkerhenderson Apr 15 '15 at 22:11
  • 1
    Certainly not the answer you were looking for 8 days ago, but Xcode 6.3.1 may resolve your issue. From the Xcode Release Notes: "Swift tests are automatically discovered by Xcode. (20373533)" via https://developer.apple.com/library/ios/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051 – Chris Droukas Apr 22 '15 at 03:42

3 Answers3

14

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.

enter image description here

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

Community
  • 1
  • 1
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
3

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:

before files before tests

After:

after files after tests

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • 1
    Thanks, your explanation makes sense, and great graphics. Xcode 6.3 doesn't seem to work, so I'm upgrading to 6.4 beta to see if that fixes it. – joelparkerhenderson Apr 22 '15 at 22:43
2

You can add and remove tests to the project easily using the class target membership checkbox. Find the class file in the Project Navigator and select it, then in the Utilities pane, click on the File Inspector and you will see a checkbox for target membership. You can toggle it on and off in there. target membership

Bryan Cimo
  • 1,268
  • 1
  • 19
  • 34