Unit testing with Swift and Obj-C

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

Then I had to manually create the bridge header and add the GA headers that I was going to use immediately. The application was launched and sent to GA. Then I tried to add some unit tests.

As soon as this happens, I get an error in my header header, which is 'GAI.h' file not found from the test target, if I add a bridge header to it. I also get a Segmentation Fault 11 error from the compiler. The error remains unchanged without a bridging header.

I tried to link my test target with SystemConfiguration, CoreData, libsqlite3, libz and libGoogleAnalyticsServices. This does not eliminate the error.

At the moment, my bridge header is not so much.

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

I also use cocoapods, but I do not use it with Google Analytics at the moment, as there were so many that I had to manually change the configuration files every time I started the swap process. If this helps here, my swap 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 have not been able to write any tests yet because I could not get the linker errors. Any ideas?

+6
source share
1 answer

As stated in my comment above, I think I had the same or similar problem: my code worked fine when I ran it, but when I tried to run the tests, I had Segfault 11 when trying to instantiate an object that references to anything from the cocoa module. I solved it in my case.

When I had an error, my Subfile looked like this:

pod 'ReactiveCocoa'

target 'MyTests' do

use_frameworks!

pod 'Quick'

pod 'nimble

end

use_frameworks! was the culprit: because use_frameworks! only in relation to the testing target, I ended the binding to ReactiveCocoa statically when building for the normal target and dynamically in the test target. I lacked some ReactiveCocoa resources that were required only with dynamic linking, but instead of the compiler, I was told that this was canceled.

My subfile now looks like this:

use_frameworks!

pod 'ReactiveCocoa'

target 'MyTests' do

pod 'Quick'

pod 'nimble

end

There were several problems with linking, but they were easy from there, because when I compiled the main goal, I got robust errors. Hope this helps someone :)

+4
source

Source: https://habr.com/ru/post/982275/


All Articles