Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can no longer import app module into unit tests after changing deployment target

For unit testing public classes of my main app target in my swift unit tests, I have to import my main app module in my tests like so:

#import MyAppModuleName

This worked just fine until I changed my deployment target from 7.0 to 8.4.

Now building and running my app still works perfectly, but running unit tests stopped working. The compiler complains about the above import statement: Swift Compiler Error: Module file's minimum deployment target is iOS8.4 v8.4

I have no clue why. Did I forget to change the deployment target somewhere else?

My workspace (Xcode 6.4.) contains my own project and a Pods project (automatically created by cocoapods). I'm using both Swift and Objective-C in my app and in my tests.

Here's what I did in more detail:

1) Changed deployment target from 7.0 to 8.4 for my project, my main target, and also for the Pods project in my workspace, and all the pods targets.

enter image description hereenter image description hereenter image description hereenter image description here

2) Cleaned the build folder (Shift+Alt+Cmd+K) and restarted Xcode.

3) Cmd+U -> Error

When changing the main app's deployment target back to 7.0, everything works fine again.

Any ideas where this problem is coming from?

like image 627
Goodsquirrel Avatar asked Jul 16 '15 17:07

Goodsquirrel


People also ask

What does @testable Import do?

There is this extra @testable import declaration. This is Apple's way of helping you import your app code into the unit test target so you can run your tests.

How do I set a target deployment?

Navigate to Infrastructure ➜ Deployment Targets and click ADD DEPLOYMENT TARGET. Select the type of deployment target you are adding. Select the type of connection your deployment target will make, and follow the on-screen instructions.

How do I set a deployment target in iOS?

Deployment Target refers to the oldest version of iOS that is capable of running your project. To change your deployment target, open up your project file in Xcode and check the setting under Build Settings -> Deployment(...) Check this answer to add earlier devices support.


1 Answers

You were almost there, you just need to update the iOS Deployment Target for your Project and both of your targets.

For your project: enter image description here

For your app target: enter image description here

For your test target: enter image description here

You should probably do a clean and rebuild, no need to restart Xcode. I guess this will also work if you want to target 8.1 etc.

like image 71
Rool Paap Avatar answered Sep 21 '22 09:09

Rool Paap