I have started working with OCMock to write test cases for the existing project that I have integrated in my project workspace. After following all the steps mentioned in this link.
When I first executed my test case it's giving the error above. I searched it and tried following some of the solutions like creating new target, restarting Xcode but it didn't help me out. Any idea?
I have my notes and demo applications for both Cocoapods and Carthage here https://github.com/onmyway133/TestTarget
Make sure all frameworks are linked to the Test targets
Configure Runpath Search Paths to point to $(FRAMEWORK_SEARCH_PATHS)
More info
Run-Path Dependent Libraries
I'm using carthage and problem for me was searching for dependencies in a test target. Fix:
Add $(PROJECT_DIR)/Carthage/Build/iOS to Runpath Search Paths
You can find reference here: Carthage issue
There might another solution, if you are using CocoaPods and the UI test target is embedded inside the app target, which is, unfortunately, the case in the default template (pod init).
Try move the UI test target out of the app target as follows:
from:
platform :ios, '11.0'
use_frameworks!
target 'MyApp' do
# Pods for MyApp
target 'MyAppUITests' do
inherit! :search_paths
# Pods for testing
end
end
to:
platform :ios, '11.0'
use_frameworks!
# Pods shared between MyApp and MyAppUITests
target 'MyApp' do
# Pods for MyApp only
end
target 'MyAppUITests' do
# Pods for testing
end
Credit goes to SpacyRicochet in this issue thread: https://github.com/CocoaPods/CocoaPods/issues/4752#issuecomment-305101269
My solution was to add a "Copy File phase" to my test target.
There I set destination to Frameworks and added my framework with the + sign.
In my case there was nothing wrong with linked files.
The Simulator was kind of stuck at the message that the app triggered, like: "App name would like to send you notifications".
Pressed OK and the next time my XCTests worked fine.
Just to share my experience about this error:
I'm using fastlane + cocoapods.
I have a workspace with 2 dynamic frameworks:
A.framework
B.framework
Dependencies:
A depends by AFNetworking using cocoapods
B depends by A
Dependency are defined in the Podfile.
The error was raised executing framework B tests.
In my case the problem was related to the missing dependency to AFNetworking in B.framework target.
Adding a pod dependency to AFNetworking in B.framework in Podfile, all was resolved.
So even if the target B is compiling successfully, AFNetworking was not embedded into the B test app and the simulator wasn't able to run B test app raising this "very meaningful" (*) error.
(*) thanks to Apple for this!
Wow, I wasted a lot of time on this, my test bundle had the "Host Application" to my application selected. Other test bundles did not.
I expect this solution may not be the right solution for every situation, but my tests were mainly to test the dynamic library and it did not really need a Host Application to run. I was getting the above error, turning this off allowed me to run the tests without getting that error and the breakpoints worked. I was running MacOS but it probably does similar for other environments. I expect this solution may not be the right solution for every situation, but my tests were mainly to test the dynamic library and it did not really need a Host Application to run.
On the test bundle Go to General -> Testing -> Set "Host Application" to None.
In my case Build Active Architecture Only was set to YES.
In project and targets :
Build Settings -> Architectures -> Build Active Architecture Only should be NO instead of YES
In my case I had not added a Run Script phase for the Quick and Nimble libraries which I integrated using Carthage.
I had the same issue and already tried everything proposed here without any success.
Running the tests on a different simulator solved the problem for me. After that, the original simulator also didn't cause fails any longer.
My case was special. I used 2 files as test classes. one worked perfectly and the other had that error.
Both link against the same framework.
Solution
CLEAR DERIVED DATA
Window => Projects => Delete (at your project)
Good luck
and happy testing!
During I was creating Cocoa Touch Framework every any attempt to run tests ended with the same error message like OP wrote.
I fixed it by changing build configuration of TEST from Debug to Release.
Step 1
Step 2
Step 3
Note: There was not need any extra configuration of Runpath Search Paths.
I am using Cocoapods in ver 1.6.1 and Xcode 10.1
If anybody still experience this issue this answer helped me. Set Always Embed Swift Standard Libraries to No in the projects settings. I did it for the UI test target.
I tried many different options but none helped me except below and wasted lot of time, posting this so that really help and save time on this:
Follow all of the instructions for Full Manual Configuration
https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md#full-manual-configuration
Tips
When you come to the part where you are executing xcodebuild, if the build fails, and the log mentions "RoutingHTTPServer" or "YYCache", add these two frameworks on the Build Phases tab of the WebDriverAgentRunner target
Open the WebDriverAgent.xcodeproj
Select 'Targets' -> 'WebDriverAgentRunner'
Open 'Build Phases' -> 'Copy frameworks'
Click '+' -> add RoutingHTTPServer
Click '+' -> add YYCache
https://github.com/facebook/WebDriverAgent/issues/902#issuecomment-382344697
https://github.com/facebook/WebDriverAgent/issues/902#issuecomment-383362376
The build/test may also fail due to the WebDriverAgentRunner app/developer being untrusted on the device. Please trust the app and try again.
While trying to access the WebDriverAgent server status, if it tries to connect on port 0, hardcode port 8100 in appium-xcuitest-driver/WebDriverAgent/WebDriverAgentLib/Routing/FBWebServer.m
Original line: server.port = (UInt16)port;
New line: server.port = 8100;
https://github.com/facebook/WebDriverAgent/issues/661#issuecomment-338900334
Would like to share my answer hope it could save someones time.
For me .m file was not properly linked under Build Phases - > Compile Sources
In my case, I had declared a property as readonly in a header file:
// In .h file
#property (nonatomic, readonly) NSUInteger count;
but I forgot to add this declaration to the .m so a setter would be generated:
// In .m file
#property (nonatomic, assign) NSUInteger count;
Silly mistake, not totally sure why it manifested in this error, but adding that line to the .m fixed the problem.
In my case, my Build Settings -> Architectures was setting only for armv7 and I changed for ARCHS_STANDARD that was the same of my Host Application
For me, I had to 'Trust' developer in 'Device Management' under 'Settings -> General' on my device. (Settings -> General -> Device Management -> DeveloperID -> 'Trust the app') As I was running app through side loading using my apple ID.
In my case I had to remove $(inherited) from Other Linker Flags in my ui test target. I have installed static libraries via cocoapods.
for me the problem was the Pod file
I made a new target but forgot add target in the pod file
target 'mobilesdkIntegrationTests' do
// write here any predefined pods if any, like
testing_pods
end
just add target in the pod file fixed the issue
There are some automatically added project settings that come with Xcode 10, and they come some of the time, not all of the time. After downloading Xcode 10, restart your computer. That is what fixed this for me. None of these answers fixed it for me. I hope this helps. I wish I could give a better answer.
Switching from Xcode 9.4.1 to Xcode 10.1 solved the problem in my case.
In my case I had completely clean project with default empty tests.
If I have added any pod I received this error.
Solution was that at least one file in Test target should import Foundation
import XCTest
import Foundation
#testable import CVZebra
class CVZebraTests: XCTestCase {
override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}
}
In my case there was an issue with my app in the simulator. Before the issue came up, I processed a db-migration (realm) which failed and destroyed my db. So everything worked fine for me after I deleted the app on the simulator.
I need to add test cases to an existing project, so I tried adding a new test target via
File -> New -> Target -> Cocoa Touch Testing Bundle
From the test navigator filter bar.
Even after adding, the target is not getting listed in the test filter bar.
May be because of this issue, Product -> Test option is diabled in my project.
Also I could see some differnce between the build setting in my project and another sample project I started in Xcode 6.1 in which Product -> Test option is enabled and everything working fine for Test cases.
Please find the build settings screen shots.
Any help is appreciated.
I had this exact problem. It turns out my existing project was creating my Cocoa Touch Testing Bundle with the .app extension when it should've been a .xctest extension.
You can fix this by going to your test target you created. Build Settings > Wrapper Extension and changing it from app to xctest.
You may have to restart Xcode after this change to select your test target.
UPDATE: I found out the reason the Testing Bundle was becoming a .app extension in the first place. I had to go to the main project Wrapper Extension and make sure it was blank instead of .app. Apparently that was forcing all targets to become .app extension as well.
So after I create an Xcode 6 project, even if I haven't written any code in it, if I try renaming it by double clicking the bolded program title in the upper left hand corner of the navigator and then confirming that I want the checked items' names changed, I get the following error when I try running it: "clang: error: linker command failed with exit code 1 (use -v to see invocation)"
I've even tried using the find tool to see all the things named the previous name, including the info.plist (which I think is the problem) and changing them to the new name. By renaming the info.plist manually I get an error saying that doesn't exist.
What am I doing wrong?
I saw the same error after changing the name, and I was able to fix it by clearing the "Test Host" values in the Build Settings of my "Tests" target:
Alternatively, If you need your tests to be able to run after changing the name of your project, you should be able to update the MyProject.app/MyProject value in both fields to reflect the new name of your project (ie. MyNewProject.app/MyNewProject)
If above method(s) doesn't work and if for now you don't feel like needing to test anything in your project, just remove your project test target.
Later on if you need to create some tests, you will still be able to add test targets again.
Go to the Build Settings of my "Tests" target then change the paths from the old project name to your new project name
Test Host
- Debug Build/Debug-iphoneos/OldProjectName.app/OldProjectName
- Release Build/Release-iphoneos/OldProjectName.app/OldProjectName
Test Host
- Debug Build/Debug-iphoneos/NewProjectName.app/NewProjectName
- Release Build/Release-iphoneos/NewProjectName.app/NewProjectName
Just simply clearing them would break your tests so you need to replace them with the new project name.
Ran into this too, after copying and renaming the folder with an xcode project. I think it's a bug in xcode. Best file a bug with bugreporter (https://bugreport.apple.com/). Removing the test target from my project fixed it for me, too.
Here is what I've done to fix the similar problem since I changed the project name and folders under the project.
Select project file : projectName.xcodeproj
Right click on the project file and click "Show package contents" to open project.pbxproj file.
Once ope project.pbxproj file, replace all from old project name (whatever you changed from) to new name.
You can change the name of sub folder if you changed folder name too.
Hope this help.
There are different places where you should check for the rename.
You should check for the "old" project name in the test target and in the project target. Search for the old name string and rename them manually to the new name.
If you doesn't use the test target you can delete this target.
There are many places you have to check upon re-naming. This approach does not seem at all practical.
If you really need to do this, I recommend creating a new project and just copying the necessary files over to the new project.
I'm using libxml in a project. I had an issue before where the app would not compile due to a "Lexical or Preprocessor issue" in which the file libxml/tree.h could not be found. I fixed this by copying the library into my projects root folder and adding the Header Search Path: "${SDKROOT}/usr/include/libxml2".
This fixed the original issue. However, whenever my unit tests have a dependency on any part of the project with an ultimate dependency upon libxml2, the same problem occurs. My project still compiles fine, just not when I'm try to run unit tests.
I'm quite new to objective-c/iOS so I'm really clueless. Any help would be greatly appreciated. Thanks!
So it turns out that I had set the header search path "${SDKROOT}/usr/include/libxml2" in the main app target, but in order to use the library in my unit tests the header search path must also be set in the "[App name]Tests" target settings.
I was reading the document of XCTest(and personally i think the documentation for this part is not that enough) and I thought I should give it a try for a new project(a MAC command-line project, not and iOS project). and then I faced complaints about linking issues--the test case building failed because the conresponsding class .o(if I am not wrong) files are not found. (the error mes here was not recorded by me, sorry)
Then I wanted to delete the test project and in the end I did not even manage to remove the test project. So seriously, how to remove an exsiting project from the solution if the notion in VS applies here?
After failing at that, I removed the auto-generated test file and created my own test case file and strangely, although Xcode detects the existence of the new test case and test method, the build failed and it failed with no issues--no linking issue, no syntax or whatever issue but it just failed. Now I do not know how to move on now as I do not even get a complaint or an error.
I don't know enough about the state of your project to be certain what the problem is, but here is something to consider: If Xcode added a new build target for your tests, be sure that the .m files that contain the classes you are testing are included in the new build target. You can do this by clicking on the relevant .m file in the Project Navigator and looking at the "Target Membership" in the File Inspector pane. Make sure the box is checked next to the test target.