如何为单元测试设置一个Swift + Objective-C项目 [英] How should a Swift + Objective-C project be setup for Unit Testing

查看:78
本文介绍了如何为单元测试设置一个Swift + Objective-C项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现很难找到如何在Xcode 6b4中配置测试目标的方法.在这种情况下,有人能指出我正确的方向吗?

I'm finding it very hard to find out how to configure test targets in Xcode 6b4. Can someone point me in the right direction given this scenario.

我有一个主要是Swift项目.但是,存在一些第三方的Objective-C依赖关系,这些依赖关系被放入应用程序的桥接标头中.我想为我的Swift代码编写测试.理想情况下,在Swift中.我的问题是这个...

I have a mostly Swift project. However, there are some 3rd party Objective-C dependencies, which get put into the application's bridging header. I want to write tests for my Swift code. Ideally, in Swift. The problem I have is this....

  1. 如果我创建一个Swift测试用例,则编译器会抱怨它无法在应用程序的桥接头中找到Objective-C头.

  1. If I create a Swift test case, then the compiler complains that it can't find the Objective-C headers in the application's bridging header.

如果创建一个Objective-C测试用例,则无法导入要测试的Swift类.

If I create an Objective-C test case, then I cannot import the Swift classes which I want to test.

我唯一能做的就是编写Objective-C测试用例,它不会涉及任何Swift.由于与Objective-C的依赖关系,我无法编写纯粹的Swift代码/测试".

The only thing which I can do is write Objective-C tests cases, which don't touch any Swift. I cannot write "purely Swift code/tests" due to the Objective-C dependencies.

有人对此有任何建议或成功吗?还是这是Beta 4中的当前状态?

Does anyone have any advice or had success on this. Or is this the current state of things in Beta 4?

推荐答案

我不确定您是否仍在寻找它,因为Xcode 6不再处于beta中,但是您可以将Objective-C桥接头文件添加到目标设置中的单元测试目标.这为我解决了这个问题.

I am not sure if you are still looking for this as Xcode 6 is not in beta any more, but you can add your Objective-C Bridging Header file to your Unit Test Target in the target settings. This fixed the issue for me.

这篇关于如何为单元测试设置一个Swift + Objective-C项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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