Test target X encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted
Asked Answered
D

24

81

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?

Deficit answered 25/1, 2016 at 10:23 Comment(4)
The instructions are known to work. With the information you've provided it's not possible to diagnose the problem. Please go the build output (cmd-8), on the left side select the "Test" entry, then on the right select "Logs" on the top, then right click on "Test target X" below, select "Copy Transcript... as text", which copies the transcript onto the clipboard. Verify what's in there, and share what you can / think is relevant.Beneficial
Got the reason for above error : ".m file was not linked under Build Phases - > Compile Sources" . But now getting another error "duplicate symbol _OBJC_METACLASS_$_<Class Name> in:" after adding -ObjC flag as other linker flag.Deficit
You should only link the library once, as it is described in the documentation.Beneficial
@ErikDoernenburg can you help me here. I am not able to identify reasonPicnic
C
125

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

Constipate answered 31/3, 2016 at 20:43 Comment(9)
Adding $(FRAMEWORK_SEARCH_PATHS) to Runpath Search Paths worked for me. Cheers!Sulphide
Hey solved also for me :) can you please explain a bit more what's going on?Dendrology
Thanks! It worked, just wanted to note that Runpath Search Paths should set in framework target, not in test targetCompressor
OMG, that helped me too! Thanks!Classicism
God, is dat you? Configure Runpath Search Paths to point to $(FRAMEWORK_SEARCH_PATHS) helps me.Pitchford
Thanks, that helped me too!Lindner
Boom, I was just about to go crazy - Thank youMagel
Strange thing) It helped me too. And then I tried to remove $(FRAMEWORK_SEARCH_PATHS)... Error did come back!Rachealrachel
I think the idea of the paths in the Runpath Search Paths is that those should reside in the simulator (or device) not in the project dir. While this solves the error for simulator builds, it's not correct. You should embed all the linked frameworks instead so they will be copied to the proper directory.Ticking
T
18

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

Twinflower answered 10/6, 2016 at 11:56 Comment(1)
This solved the issue for me, many thanks! Tests weren't running on my macOS target, so I added $(PROJECT_DIR)/Carthage/Build/Mac.Leanoraleant
K
11

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

Kosey answered 28/6, 2018 at 7:38 Comment(6)
Thanks so much! but... why does this work?! and is there a bug tracking this with cocoapods?Electronic
@Sam, sorry I don't know why either. I only found this solution by trial and error. You might need to check the official CocoaPods repo for more information.Kosey
We found a cocoapod version update plus setting up our dependencies in the project (target dependency) seemed to teach Cocoapods about our dependencies and actually fix this..Electronic
Interesting. I was already using the latest CocoaPods 1.5.3 when I hit the issue. The target dependency of the UI test target was simply the application target. Nothing else. Still I had to change the Podfile to the way I posted above, so that the UI test target could launch successfully.Kosey
Do both live inside the same project?Electronic
weird but this is the only solution that worked for me.Adz
N
6

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.

Nimocks answered 12/10, 2016 at 11:31 Comment(3)
Thanks, that helped in my case. Here is the article that describes a problem medium.com/@greesce/…Wino
in short: add all frameworks, used in current, recursively.Berhley
For me UI tests was running ok on simulator, but not on real device. Adding "Copy File phase" helped, thanks!Burbot
H
5

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.

Highborn answered 25/3, 2016 at 9:20 Comment(0)
T
5

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!

Tiffanietiffanle answered 19/1, 2017 at 15:20 Comment(0)
G
3

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.

Gustav answered 29/1, 2017 at 2:2 Comment(1)
this is what fixed it for me too, thanks 🙏Circumspection
S
2

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

Splanchnic answered 27/7, 2016 at 17:55 Comment(0)
P
2

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!

Precipitate answered 30/8, 2016 at 21:54 Comment(0)
F
2

In my case I had not added a Run Script phase for the Quick and Nimble libraries which I integrated using Carthage.

Footie answered 14/7, 2017 at 4:56 Comment(0)
Q
2

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.

Quimper answered 19/8, 2018 at 17:22 Comment(0)
S
1

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

Subcontract answered 12/6, 2018 at 14:56 Comment(0)
L
1

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

enter image description here

Step 2

enter image description here

Step 3

enter image description here

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

Limestone answered 26/3, 2019 at 15:50 Comment(1)
Very strange. This worked for me as well in one project (using same versions) but another project works just fine using the Debug config to test 🤷🏻‍♂️Heaviside
F
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.

Ferrite answered 13/4, 2019 at 18:0 Comment(0)
D
0

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

Deficit answered 26/1, 2016 at 8:25 Comment(0)
A
0

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.

Aspersion answered 29/3, 2016 at 18:15 Comment(0)
M
0

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

More answered 30/6, 2016 at 18:2 Comment(0)
E
0

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.

Epidote answered 18/11, 2017 at 17:59 Comment(0)
C
0

In my case I had to remove $(inherited) from Other Linker Flags in my ui test target. I have installed static libraries via cocoapods.

Cynic answered 19/3, 2018 at 21:14 Comment(0)
M
0

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

Mintz answered 27/8, 2018 at 6:52 Comment(0)
K
0

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.

Kreitman answered 19/9, 2018 at 23:36 Comment(0)
I
0

Switching from Xcode 9.4.1 to Xcode 10.1 solved the problem in my case.

Interlocutor answered 14/1, 2019 at 10:26 Comment(0)
T
0

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.
        }
    }

}
Translucent answered 23/1, 2019 at 14:50 Comment(0)
C
0

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.

Coroner answered 15/4, 2019 at 6:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.