将 Swift 单元测试添加到混合语言 Xcode 项目

编程入门 行业动态 更新时间:2024-10-25 22:27:03
本文介绍了将 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.

推荐答案

twitter/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 项目

本文发布于:2023-11-14 11:30:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587095.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元测试   语言   项目   Swift   Xcode

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!