Can't import main swift classes into test target?
I am trying to test the classes in my iOS app. I am trying to import the target
Pickle in my app that has all my classes into my testing target
PickleTests by adding
import Pickle to the top of my
PickleTests.swift testing file, but I keep getting an error.
The error I keep receiving is: “Failed to import bridging header (path to bridging header)” (the path to the bridging header is shown in the error, not the parentheses).
I have tried setting “Defines module” in my build settings for
Pickle target to “Yes”, but it still doesn’t work. I have also verified in the build settings that it has the correct path to the bridging header file.
Any ideas as to how I can set up my testing? I am on Xcode 6.3.2. Please let me know if you need any additional info.
Open the image in a new tab to see it larger.
- XCTest not registering new methods as tests
- XCTestCase waitForExpectationsWithTimeout:handler: throwing EXC_BAD_ACCESS when expectation is not fulfilled
- XCTest and asynchronous testing in Xcode 6
- Adding test target to an existing project is not working
- Scheme language setting ignored in iOS unit and ui tests
- failing a XCTestCase with assert without the test continuing to run but without stopping other tests
3 Solutions Collect From Internet About “Can't import main swift classes into test target?”
Many thanks to @matt for helping me with this one!
Right click on the images and open them in a new tab to see them larger.
As discussed on https://github.com/CocoaPods/CocoaPods/issues/2695 the issue seemed to be lying with having Cocoapods as part of the project. The answer near the bottom of the link that solves the issue involves clicking on your Application settings, and then clicking on your Project
Info (not any of your targets’ settings). There you will see your
You will also notice that there are two targets in the config settings, and that your Testing Target config settings will be set to none while your Main Target will be linked to the Cocoapods. The fix lies in changing that
None value next to the Testing Target to the same thing that the Main Target has:
So now they are both linked to the Cocoapods. Making sure your main target has
Defines module set to
Yes in its
Build Settings, build your project and the error in the testing files should go away.
Also, after I did this fix I encountered another error where the linker was throwing an error complaining about missing a library in my testing target. This missing library was another dependency I had in my project, and I solved this error by making sure all of my dependencies that were linked in my Main Target’s
Link Binary with Libraries in its
Build Phases settings were copied over to the Testing Target’s
Link Binary with Libraries in its
Build Phases settings.
You don’t have to do this. You can use link_with in your Podfile. In your case you would do.
link_with 'Pickle', 'PickleTests'
FWIW, on Xcode 7, import with the annotation: @testable.
import Pickle @ImportTests
Then you’ll be able to see the classes in code completion and compiling.
- Creating Qt 5.1 apps for iOS
- XCode instruments not reporting any data
- How can i decrypt signature and add to the YouTube Extracted URL in objective c?
- XCode Application Loader – ERROR ITMS-9000 Invalid Provisioning Profile
- Multiple web service calls on same viewController iphone
- How to change the color of a UIBezierPath in Swift?
- in Swift, what does this specific syntax mean?
- How to use NSXMLParser to parse parent-child elements that have the same name
- Xcode A+ source control symbol
- Can an Obj-C AXObserverCallback be converted to Swift?
- @class May I know the proper use of this
- Pass data through unwind segue
- Convert unicode
- Xcode 4 – Is there something in Interface Builder like “reveal in canvas”?
- watchOS – Complication shows previous entry