stackflow
stackflow

Reputation: 2122

Swift Unit Test Error - framework not found AWSCore for architecture i386

I have Swift 2.3 project working fine with AWS Libraries. I just tried to create a sample unit test for this and I get this error. It seems my unit test class cannot find the frameworks I installed using a Podfile

This is the unit test class

import XCTest
import UIKit
@testable import safetyv1


class OffenceFormVCTests: XCTestCase {
    
    var vc:OffenceFormVC!
    
    override func setUp() {
        super.setUp()
        // called first
        vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("OffenceFormVC") as! OffenceFormVC
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }
    
    
    
}

This is the error I get when I do Product > Build for > Testing enter image description here

And my build settings enter image description here

Podfile
enter image description here

Anyone knows how to fix this issue? Thanks a lot!

Upvotes: 8

Views: 4264

Answers (3)

Alexander Vasenin
Alexander Vasenin

Reputation: 12953

I was able to work around of this problem by setting FRAMEWORK_SEARCH_PATHS of my test target to

$(inherited)
"$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/AWSCore"

I can't understand Xcode adds -framework AWSCore to test target linker (OTHER_LDFLAGS is empty).

Upvotes: 0

JP Lno
JP Lno

Reputation: 91

I issue the exact same problem and pass one day to find the answer.

Problem is that when you add your project with cocoapod, you add pod to your project only.

So to solve this issue you need to add this in your PodFile:

target :'YourPojectTests' do
pod 'AWSAutoScaling'
pod 'AWSCloudWatch'
pod 'AWSCognito'
pod 'AWSCognitoIdentityProvider'
pod 'AWSDynamoDB'
pod 'AWSEC2'
pod 'AWSElasticLoadBalancing'
pod 'AWSIoT'
pod 'AWSKinesis'
pod 'AWSLambda'
pod 'AWSMachineLearning'
pod 'AWSMobileAnalytics'
pod 'AWSS3'
pod 'AWSSES'
pod 'AWSSimpleDB'
pod 'AWSSNS'
pod 'AWSSQS'
end

and replace "YourProjectTests" by your project tests name bundle

Just need to do :

pod update

And open your project.workspace on Xcode to get it working.

Safe check is to go in your projecNameTests settings and check that all -framework are set in linker section as shown like in yourProject settings

Enjoy

Upvotes: 2

Sn0wfreeze
Sn0wfreeze

Reputation: 2031

I had the same problem it seems to be an easy fix. Just add your testing target in your podfile as another target withe same pods.

Your podfile should contain something like this:

target: 'safetyv1Tests' do
   pod 'AWSCore' 
   pod 'AWSS3' 
end 

For Carthage you need to add the frameworks to the test target

Greetings, Alex

Upvotes: 5

Related Questions