与第三方图书馆和迦太基进行单元测试 [英] Unit testing with third party libraries and Carthage

查看:79
本文介绍了与第三方图书馆和迦太基进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用迦太基进行依赖关系管理的正确方法是什么,同时又能够为其引入的类型编写测试.例如,(这是假设的)如果我引入AlamoFire并假设它具有一个Response协议和不同的具体类型都符合Response协议.在我自己的图书馆中,如果我愿意的话

What is the proper way to use Carthage for dependency management, but also be able to write tests with it for types it pulls in. For example, (this is hypothetical) if I pull in AlamoFire and let’s say it has a Response protocol and different concrete types conform to the Response protocol. In my own library, if I were to do

   @testable import AlamoFire 

它会抱怨模块'AlamoFire'没有编译用于测试.做一些研究,我相信是因为在发布版本中启用可测试性应该设置为NO,而迦太基默认使用该版本.有没有办法在测试目标中使用像这样的第三方类型?

it would complain that Module ‘AlamoFire’ was not compiled for testing. Doing some research, I believe it’s because enable testability should be set to NO on release builds, which Carthage uses by default. Is there a way to use third party types like this in your test target?

推荐答案

使用 import 代替 @testable import 来访问模块的公共类型.

Use import instead of @testable import to access a module's public types.

还要在测试目标的构建阶段中,将AlamoFire添加到将二进制文件与库链接"

Also in your test target's Build Phases, add AlamoFire to "Link Binary With Libraries"

这篇关于与第三方图书馆和迦太基进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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