Double check that the file in question is not in the main target but instead only the test target. Only the test target will have that framework to import.
The main project does not link with the XCUnit framework. You should create a separate testing target for your project, if one does not already exist, and add your test source files to that target.
If you are working on an iOS project template, select iOS > Test > iOS Unit Testing Bundle
.
If you are working on an OS X project template, select OS X > Test > OS X Unit Testing Bundle
.
You've just added your tests file/class into main target and not into test target by mistake. Simple as that.
Solution:
1) Remove test file from "Compile Sources" list on "Build Phases" tab for main target
2) Add same file into "Compile Sources" on "Build Phases" tab for test target
It must resolve the issue
I get this error if I create a macOS dynamic framework target, which links to XCTest.framework
(the target is a framework target, not a testing target!).
In this case the problem is solved by adding
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks
to project's "Build Settings / Framework Search Paths".
After lots of troubleshooting and bouncing around Stack Overflow pages such as this one, I managed to find one detail that was not mentioned on the other iOS Unit Test troubleshooting pages.
If your project uses CocoaPods, make sure to include your test target nested inside your main application's target. Your podfile might not include it if you created your test target after running pod init
. Your podfile should look something like this:
target 'YourApp' do
target 'YourAppTests' do
inherit! :search_paths
# Pods for testing
end
end
Remember to save your podfile and run pod install
after doing so.
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With