将 Xcode 的测试类助手编辑器与 Swift 类一起使用 [英] Use Xcode's Test Classes Assistant Editor with Swift Classes

查看:25
本文介绍了将 Xcode 的测试类助手编辑器与 Swift 类一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Xcode 中工作时,在助理编辑器中提取单元测试用例通常很好.目前,我一直在手动选择测试文件,但我看到助理编辑器有一个 Test Classes 选项.

When working in Xcode, it's often nice to pull up unit test cases in an assistant editor. Currently, I've been selecting the tests file manually, but I see the assistant editor has an option for Test Classes.

我已尝试使用此选项自动提取我的测试文件,但似乎无法使其正常工作.它是否需要某种配置?它只是不适用于 swift 项目吗?

I've tried to get this option to pull up my tests file automatically, but I can't seem to make it work. Is there some sort of configuration required for it? Does it just not work for swift projects?

推荐答案

其他答案中提到的快捷方式效果很好,但它们不会使助理编辑器自动与测试类一起工作.原来它以前不适用于 swift 代码,但 Apple 刚刚在 Xcode 9 中添加了对此的支持:

The shortcuts mentioned in other answers work great, but they don't make the assistant editor automatically work with test classes. Turns out it didn't work with swift code previously, but Apple just added support for this to Xcode 9:

基本名称为 FooTest 或 FooTests 的文件现在被视为基本名称为 Foo 的文件的对应物,用于导航和助理编辑器.(28981734)

A file with a base name of FooTest or FooTests is now considered a counterpart of a file with a base name of Foo for navigation and the Assistant Editor. (28981734)

因此,对于 Xcode 9,测试目标文件名需要与主代码文件同名 + 'Test' 或 'Tests',Xcode 测试类辅助编辑器将自动工作.

So, with Xcode 9, the test target filename needs to have the same name as the main code file + either 'Test' or 'Tests' and the Xcode test classes assistant editor will work automatically.

这篇关于将 Xcode 的测试类助手编辑器与 Swift 类一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆