Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete an Xcode Swift Test Class from the Test navigator?

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.

like image 589
joelparkerhenderson Avatar asked Apr 13 '15 19:04

joelparkerhenderson


People also ask

How do I delete a test target in Xcode?

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.

How do I disable tests in Xcode?

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.

What is XCTest Swift?

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.

How do I add tests to Xcode?

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.


Video Answer


2 Answers

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

  • How to do a Unit Test in Xcode
  • Xcode UI Test example
like image 156
Suragch Avatar answered Oct 13 '22 23:10

Suragch


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 filesbefore tests

After:

after filesafter tests

like image 35
Caleb Avatar answered Oct 14 '22 00:10

Caleb