如何为 Swift 设置单元测试? [英] How do I setup a Unit Test for Swift?

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

问题描述

我觉得尝试掌握单元测试/Swift 是明智之举.
我查看了 WWDC 的 Objective-C 版本,并且非常了解 Objective-C 范式:导入单元测试所依赖的标头等.

单元测试不知道fetchFlickrPhotoWithSearch()".所以...

由于单元测试模块/目标超出了应用程序目标的范围,我假设我需要导入具有我希望测试的功能的特定 Swift 文件(类似于 Objective-C 的标头范例).

但是编译器将此导入标记为没有这样的模块..."

那么...如何让我的 Swift API 可用于单元测试?

I feel it prudent to attempt to master Unit Testing/Swift.
I viewed WWDC's Objective-C version and pretty much understand the Objective-C paradigm: importing the headers that the Unit Test depends on, etc.

The 'fetchFlickrPhotoWithSearch()' is unknown to the Unit Test. So...

Being that a Unit Test module/target is outside the scope of the application target, I assume that I need to import the particular Swift file (similar to Objective-C's header paradigm) that has the functions I wish to test.

But the compiler flags this import as 'No such module...'

So... how do I make my Swift APIs available to the unit test?

推荐答案

这里有一个很好的 tut:

There is a good tut here:

http://natashatherobot.com/swift-unit-testing-tips技巧/

确保您要测试的类文件在实用程序面板的文件身份检查器中检查了测试的目标成员资格.这是我第一次看到.

Making sure the class file you want to test has it's target membership checked for Tests in the file Identity inspector in the utilities panel. This caught me the first time.

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

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