将 Swift 单元测试添加到混合语言 Xcode 项目 [英] Adding Swift Unit Tests to a Mixed Language Xcode Project

查看:50
本文介绍了将 Swift 单元测试添加到混合语言 Xcode 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置单元测试来测试添加到以前仅支持 Objective-c 的项目中的 Swift 类?

How do you set up unit tests to test Swift classes added to a previously Objective-c only project?

我已将 Swift 类添加到我的项目中,并且能够在其他 Swift 和 Objective-c 文件中使用它们;但是,我无法从我的测试类访问它们.

I've added Swift classes to my project and am able to work with them in other Swift and Objective-c files; however, I'm unable to access them from my test classes.

我认为正确的导入语句是 @testable import MyAppModuleName,它是添加到 Xcode 模板中的示例测试类的内容.该行产生的错误是无法导入正在编译的模块.此错误出现在使用 Swift 2 的 Xcode 7 中.

The import statement I believe is correct is @testable import MyAppModuleName which is what is added to the example test class in Xcode's templates. The error produced by that line is Cannot import module being compiled. This error is in Xcode 7 using Swift 2.

推荐答案

https://twitter.com/UINT_MIN 提供的答案

就我而言,两个目标(应用程序和测试)在构建设置中具有相同的模块名称.更改测试目标的模块名称解决了问题.

In my case the both targets (the application and the tests) had the same module name in the build settings. Changing the module name of the test target resolved the issue.

这篇关于将 Swift 单元测试添加到混合语言 Xcode 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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