如何从测试导航器中删除 Xcode Swift 测试类?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29613268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to delete an Xcode Swift Test Class from the Test navigator?
提问by joelparkerhenderson
The Xcode Test navigator shows a list of test case classes.
Xcode 测试导航器显示测试用例类列表。
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.
我尝试了许多典型的方法,例如按删除键,或查找“-”图标或“删除”菜单项,或在 Apple Xcode 文档中搜索帮助。
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.
在项目导航器中,从项目中移除文件并删除该文件。
退出 Xcode 并重新启动它。测试导航器似乎无法跟踪测试类和测试用例,并显示零项。
运行测试。测试导航器似乎重建了测试类和测试用例的列表。
If that still doesn't work, try these...
如果这仍然不起作用,请尝试这些...
Delete Xcode Derived Data:
删除 Xcode 派生数据:
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.
Xcode 菜单 -> 首选项 -> “位置”图标 -> “派生数据”部分。
单击灰色的小圆圈箭头;这将打开 Finder 并显示 DerviedData 文件夹。
删除整个文件夹。
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.?
有没有更简单的方法来实现删除测试类的目标?理想情况下不需要重新启动 Xcode,或重建项目等?
Related kind of issue: How can I delete Xcode test cases from the test case view?
相关类型的问题:如何从测试用例视图中删除 Xcode 测试用例?
I'm using Xcode 6.3 and Swift 1.2, if that helps to know.
我正在使用 Xcode 6.3 和 Swift 1.2,如果这有助于了解的话。
Edit: In the comments, @CouchDeveloper points to the official Xcode 6.3 release notes, which describe a known bug # 20373533:
编辑:在评论中,@CouchDeveloper 指向官方Xcode 6.3 发行说明,其中描述了一个已知错误 #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. ...
在此版本的 Xcode 中不会自动发现 Swift 测试。不会出现源代码编辑器侧栏中的测试注释,并且方案表的测试操作中的测试导航器和测试表将为空。...
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.
这个问题的悬赏是针对任何解决方案或更好的解决方法。任何解决方法都可以,例如使用 Xcode GUI,或使用命令行 xcodebuild,或任何包含项目文件的 shell 脚本。
回答by Suragch
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.
如果您只想删除一个测试类,您可以在 Project Navigator 中单击文件名,然后按 Delete 和 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.
在您的项目中进行单元测试(和 UI 测试)是个好主意。因此,如果您想重新添加它们,只需单击加号 (+) 按钮即可。
See also
也可以看看
回答by Caleb
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.
使用 Xcode 6.2,我所要做的就是切换到项目导航器,选择文件,然后按删除。然后我在出现的确认对话框中单击了“删除引用”按钮。之后,该文件中的测试立即从测试导航器中消失。重新添加文件,测试再次出现。
I didn't have any need to delete the derived data folder, restart Xcode, etc.
我没有任何需要删除派生数据文件夹、重新启动 Xcode 等。
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).
这当然是所需的行为,听起来它在 Xcode 6.3 中已损坏,但可能在 6.3.1 中再次修复。因此,真正的答案可能只是您需要升级到 6.3.1(或降级到 6.2)。
Before:
前:
After:
后:
回答by Bryan Cimo
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.
您可以使用类目标成员资格复选框轻松地向项目添加和删除测试。在 Project Navigator 中找到类文件并选择它,然后在 Utilities 窗格中,单击 File Inspector,您将看到目标成员资格的复选框。你可以在那里打开和关闭它。