无法将App Delegate转换为测试中的App Delegate [英] Cannot cast App Delegate to App Delegate in Tests
问题描述
我在Swift中进行单元测试,遇到了问题。每次运行测试时,都会收到错误:
I'm doing Unit Tests in Swift, and am running into a problem. Every time I run the tests, I get the error:
Could not cast value of type 'app.AppDelegate' to 'app_Tests.AppDelegate'
我确保从测试包中取消选中AppDelegate,并且视图控制器不能再次访问应用程序委托。有没有人有解决这个问题的方法。提前致谢!
I made sure that the AppDelegate was unchecked from the tests bundle, and the view controllers cannot access the app delegate anymore. Does anyone have a solution to this problem. Thanks in advance!
推荐答案
我认为您的视图控制器
已检查测试包中的目标成员资格
。在这种情况下,您查看控制器
使用您的测试模块和App委派您的真实模块。
I think your view controllers
has checked target membership
in your test bundle. In this case you view controllers
uses your tests module and App Delegate your real module.
如果你的测试文件中有 @testable import< module name>
顶部,您的应用名称,例如 app
。那么你应该有能力使用你的视图控制器
而无需检查目标成员资格
进行测试。
If you have in your test file @testable import <module name>
in the top, where your app name, for example app
. Then you should have ability to your view controllers
without checked target membership
for your tests.
这款产品附带于2015年9月发布的Swift 2.0。
This thing comes with Swift 2.0 that was released in September 2015.
这篇关于无法将App Delegate转换为测试中的App Delegate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!