Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot cast App Delegate to App Delegate in Tests

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' 

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!

like image 646
user2201164 Avatar asked Aug 11 '15 21:08

user2201164


1 Answers

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.

Target Membership

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.

This thing comes with Swift 2.0 that was released in September 2015.

like image 175
Alexander Zimin Avatar answered Nov 02 '22 08:11

Alexander Zimin