6

I'm starting a new Swift project and I'm trying to create unit tests for it. I added the Google Analytics framework to the project and linked SystemConfiguration, CoreData, libsqlite3, libz, and libGoogleAnalyticsServices.

I then had to manually create a bridging header and added the GA headers I was going to use immediately. The app was up and running and posting to GA. I then tried to add some unit tests.

Once this happens I receive an error in my bridging header that 'GAI.h' file not found from the test target if I add a bridging header to it. I also receive a Segmentation Fault 11 error from the compiler. The error remains the same without a bridging header.

I have tried linking my test target with SystemConfiguration, CoreData, libsqlite3, libz, and libGoogleAnalyticsServices. This does not get rid of the error.

There is not much to my bridging header at the moment.

#import "GAI.h"
#import "GAILogger.h"
#import "GAITrackedViewController.h"
#import "GAIFields.h"

I'm also using cocoapods but I'm not using it with Google Analytics at the moment since there was so much I needed to manually change in the config files every time I would run the pod process. If it helps here is my pod file:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.1'

pod 'JVFloatLabeledTextField'

# Swift Pods
pod 'Alamofire'
pod 'JSONHelper'

target 'example' do

end

target 'exampleTests' do

pod 'Quick', :git => "https://github.com/Quick/Quick"
pod 'Nimble', :git => "https://github.com/Quick/Nimble"

end

I haven't been able to write any tests yet because I'm not able to get passed the linker errors. Any ideas?

3
  • 3
    I feel like Quick and Nimble should be in reverse order, followed by Jumped over the candle stick. Commented Feb 10, 2015 at 15:20
  • @James_Andreww did you ever figure this out? I'm encountering exactly the same issue: my code runs fine, and my tests run fine as long as I don't instantiate anything that references a cocoa pod: as soon as I reference a cocoa pod I get SegFault 11 on compilation. Commented May 15, 2015 at 21:07
  • @MichelleEllis unfortunately my fix was to create a brand new project and re-add all of my files. Once I did this I was able to test again with cocoapods code. Commented May 17, 2015 at 17:33

1 Answer 1

4

As stated in my comment above, I think I experienced the same or a similar issue: my code worked fine when I ran it, but when I tried to run tests, I got a Segfault 11 on trying to instantiate an object that referenced anything from a cocoa pod. I've solved it in my case.

When I had the error, my Podfile looked like this:

pod 'ReactiveCocoa'

target 'MyTests' do

use_frameworks!

pod 'Quick'

pod 'Nimble

end

use_frameworks! was the culprit: because use_frameworks! only applied to the testing target, I ended up linking to ReactiveCocoa statically when building for the normal target, and dynamically in the test target. I was missing some ReactiveCocoa imports that were required only when linking dynamically, but instead of the compiler telling me that it segfaulted.

My Podfile now looks like this:

use_frameworks!

pod 'ReactiveCocoa'

target 'MyTests' do

pod 'Quick'

pod 'Nimble

end

There were a few linking issues to work out but they were easy from there, because when I compiled the main target I got sane errors. Hopefully this helps someone :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.