Since Xcode 26 our tests are crashing due to the Main Thread not being able to deallocate WKNavigationResponse.
Following an example:
import Foundation
import WebKit
final class WKNavigationResponeMock: WKNavigationResponse {
    private let urlResponse: URLResponse
    override var response: URLResponse { urlResponse }
    init(urlResponse: URLResponse) {
        self.urlResponse = urlResponse
        super.init()
    }
    convenience init(httpUrlResponse: HTTPURLResponse) {
        self.init(urlResponse: httpUrlResponse)
    }
    convenience init?(url: URL, statusCode: Int) {
        guard let httpURLResponse = HTTPURLResponse(url: url, statusCode: statusCode, httpVersion: nil, headerFields: nil) else {
            return nil
        }
        self.init(httpUrlResponse: httpURLResponse)
    }
}
import WebKit
import XCTest
final class ExampleTests: XCTestCase {
@MainActor func testAllocAndDeallocWKNavigationResponse() {
  let expectedURL = URL(string: "https://galaxus.ch/")!
  let expectedStatusCode = 404
  let instance = WKNavigationResponeMock()
// here it should dealloc/deinit `instance` automatically
}
Here the call stack:
Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   CoreFoundation                	       0x101f3dd54 CFRetain.cold.1 + 16
1   CoreFoundation                	       0x101e14860 CFRetain + 104
2   WebKit                        	       0x10864dd24 -[WKNavigationResponse dealloc] + 52
                    
                  
                XCTest
RSS for tagCreate and run unit tests, performance tests, and UI tests for your Xcode project using XCTest.
Posts under XCTest tag
            
              
                88 Posts
              
            
            
              
                
              
            
          
          
  
    
    Selecting any option will automatically load the page
  
  
  
  
    
  
  
              Post
Replies
Boosts
Views
Activity
                    
                      I am trying to upgrade my app to use Xcode 26 and I cannot get my tests to launch.
I am trying to launch tests to the simulator, and I always get this error after 300 second timeout:
"encountered an error (The test runner hung before establishing connection.)"
There are no other errors getting logged.
I can run to the same simulator just fine, and in Xcode 16 the tests launch with no issues.
The tests also run fine on an actual iPhone.
Thanks in advance.
                    
                  
                
                    
                      Fails to gather code coverage and throws this error
Showing All Messages
Failed to merge raw profiles in directory /Users//Library/Developer/Xcode/DerivedData/Receiver-ekqrbpsaciuxmlfslviajhoecyat/Build/ProfileData/0B0C6B69-FD46-4801-B106-56B7FCD44370 to destination /Users//Library/Developer/Xcode/DerivedData/Receiver-ekqrbpsaciuxmlfslviajhoecyat/Build/ProfileData/0B0C6B69-FD46-4801-B106-56B7FCD44370/Coverage.profdata: Aggregation tool '/Users/shwethamugeraya/Downloads/Xcode 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/llvm-profdata' failed with exit code 1: warning: /Users/shwethamugeraya/Library/Developer/Xcode/DerivedData/Receiver-ekqrbpsaciuxmlfslviajhoecyat/Build/ProfileData/0B0C6B69-FD46-4801-B106-56B7FCD44370/2F4EFBF7-1CCF-4E9E-8FD6-482EEDB98B6C-34646.profraw: raw profile version mismatch: Profile uses raw profile format version = 4; expected version = 8
PLEASE update this tool to version in the raw profile, or regenerate raw profile with expected version.
error: no profile can be merged
                    
                  
                
                    
                      The buttons in the navigation bar are not available in the element tree after iOS 26 upgrade of the test phones. The same IPA version, the same XCode version, but different trees on different phones. There is no way to automate UI testing for these missing buttons.
# ios 18
NavigationBar, 0x108e0c3c0, {{0.0, 47.0}, {390.0, 44.0}}, identifier: 'Profile'
  Button, 0x108e0c500, {{8.0, 47.0}, {43.0, 44.0}}, identifier: 'UserProfileSceneViewController_profile_back_button', label: 'chevronLeftIcon'
  StaticText, 0x108e0c640, {{169.3, 58.0}, {51.3, 22.0}}, label: 'Profile'
  Button, 0x108e0c780, {{339.0, 47.0}, {43.0, 44.0}}, identifier: 'UserProfileSceneViewController_settings_bar_button', label: 'Settings'
# ios 26
NavigationBar, 0x13d63c8c0, {{0.0, 47.0}, {428.0, 54.0}}, identifier: 'Profile'                  
  StaticText, 0x13d63ca00, {{188.3, 58.0}, {51.3, 22.0}}, label: 'Profile'
                    
                  
                
                    
                      Looking for a way to overcome this issue when starting UI tests that used to be working:
Source was stale 337 times within the last 500 ms (12 (latestGeneration) != 22 (lastKnownShmemState)): CFPrefsPlistSource<0x600003004c60> (Domain: com.apple.Accessibility, User: kCFPreferencesCurrentUser, ByHost: No, Container: ###/data, Contents Need Refresh: Yes)
...
Failed to initialize for UI testing: Error Domain=XCTDaemonErrorDomain Code=18 "Timed out waiting for AX loaded notification" UserInfo={NSLocalizedDescription=Timed out waiting for AX loaded notification}
Message from debugger: killed
The environment is Xcode 16.3 with iOS Simulator 18.0. Not using the latest Simulator 18.4 because of another bug with network requests: https://developer.apple.com/forums/thread/777999
                    
                  
                
                    
                      Xcode is throwing an error when attempting to report test coverage after running unit tests.
Showing All Messages
Failed to merge raw profiles in directory /{my project dir}/DerivedData/{my project name}/Build/ProfileData/A98EC493-3AB4-4B1C-B7FC-BC5D77B23EE3 to destination /{my project dir}/DerivedData/{my project name}/Build/ProfileData/A98EC493-3AB4-4B1C-B7FC-BC5D77B23EE3/Coverage.profdata: Aggregation tool '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/llvm-profdata' failed with exit code 1: warning: /{my project dir}/DerivedData/{my project name}/Build/ProfileData/A98EC493-3AB4-4B1C-B7FC-BC5D77B23EE3/997F01E3-3735-4897-AE00-31EBB0A9E8D3-57885.profraw: invalid instrumentation profile data (file header is corrupt)
error: no profile can be merged
Anyone else seeing this issue?
                    
                  
                
                    
                      I have an environment variable set in an xctestplan for a set of unit tests that I access like so:
let testType = ProcessInfo.processInfo.environment[TARGET_TEST_TYPE_KEY]
This is always is always returning nil when I run my unit tests in Xcode 26, but seems to work as expected in Xcode 16.4. Were there any changes in Xcode 26 that changes how this works?
Thanks in advance.
                    
                  
                
                    
                      I run some tests for an iOS app, connecting the iPhone to my mac where the code resides.
I notice that it fills the iPhone from system data, until the iPhone is full.
I tried everything to remove the system data (I assume some logs from the XCode testing): reset network, restart the iPhone, remove the tested app, etc. Nothing works. I am stuck with having to erase all data on the iPhone and reinstall from scratch, which is very tedious.
Any suggestions ? Thanks!
                    
                  
                
                    
                      I'm trying to write performance tests with Xcode 15, but it's not working: even though setting a baseline seems to work (baseline data files are created), Xcode seems to ignore that baseline altogether whenever the test is run.   As a result, performance tests never fail, no matter how bad performance gets.
The source editor persistently displays a “No baseline average for Time” message.
Has anyone else encountered this? Figured out how to sidestep the issue?
Of note, the issue is easily reproduced: create a new (macOS in my case) app project with tests, add a dummy performance test; run the test once and save its baseline, and despite this subsequent tests will always succeed, even if you significantly slow the dummy test down.
(I've filed this as FB13330139)
                    
                  
                
                    
                      I have a project inside the project structure. I have around 300 unit tests in the project.
I see that for some of the subprojects, the coverage numbers show up correctly, but for other subprojects and the main project, the coverage number shows zero, even though the tests are running successfully.
The log I get is:
Aggregation tool emitted warnings:
warning: /Users/ABC/Library/Developer/Xcode/DerivedData/projectABC-hfzmkbdgpiswoxfvvnvhrafaiqyb/Build/ProfileData/A8EEC1FB-1699-4C29-A88C-D3DDA226DBC0/0A416494-A393-4319-AA47-502D72084C9C-43351.profraw: raw profile version mismatch: Profile uses raw profile format version = 8; expected version = 10
PLEASE update this tool to the version in the raw profile, or regenerate the raw profile with the expected version.
I only have one Xcode (26.0.1) on my machine. I tried cleaning the derived data, the cleaning project, and rerunning the tests, but it hasn't helped.
Please help me get the coverage number back. Thank you.
                    
                  
                
                    
                      Hi community:
I noticed that each closure is counted as lines in code coverage (unit tests) (Xcode 14.1.0) in a swiftUI File. I mean, If you coded and VStack that involves another HStack, and HStack contains 4 lines, and the VStack contains 6 lines counting the HStack. The total executable lines should be 6 (6 lines in the file). But Xcode count 10, counting twice the HStack lines.
Is it a bug, or is it correct? You know, I don't know if Apple has another concept about executable lines.
Also, Is it possible to remove previews with any configuration from code coverage or constant files?
Thanks for all.
                    
                  
                
                    
                      The launch argument -com.apple.TipKit.HideAllTips 1 does not work if it is defined in xctestplan arguments passed on launch.
I tested it with the apple provided example app, where I created simple UI test and added xctestplan with launch argument -com.apple.TipKit.HideAllTips 1.
The app does not hide the tips when it is running the UI Tests.
Is there any solution that works?
Thanks for reply.
                    
                  
                
                    
                      Hello,
I'm unable to run any test cases in Xcode 16 with the iOS 18 simulator.
Steps to Reproduce:
Create a new iOS project in Xcode 16 using the default iOS app template with the testing option checked.
Run any test or UI test case by clicking the "Play" icon in the Test navigator.
Xcode gets stuck at the "Testing" state indefinitely.
Environment:
macOS 15 beta 8
Xcode 16 beta 6
iOS 18 beta 7 simulator
                    
                  
                
                    
                      Hi!
I must be missing something. I am creating a MacOS dynamic library using Xcode. I have created the library as follows:
File->New Project then choose macOS 'Library' in Frameworks and Libraries.
I give the Product Name "TestLib".
Framework: STL (C++ Library)
Type: Dynamic
This creates a default library project, with one exported class 'TestLib'. There's a method "HelloWorld". And this suffices for my issue.
To be able to test my dynamic library, I want to use an XCtest target.
So in the project settings, I select '+', and add a 'Unit Testing Bundle':
Product name: TestLibTests
Language: Swift
Testing System: XCTest
Project: TestLib
Target to be tested: TestLib
I press finish, and my test target is created.
Now, I think I need to have a module map. So I Add New File From Template', and choose 'Module Map'. A 'module.modulemap' is created. In the module map file, I name the module 'TestLib', and header 'TestLib.h'.
So far, everything makes sense, and no errors. But here it comes...
When I want to make a testcase, I need to import the module. I first built the dylib library, to make sure it's built without errors and exists.
Then I switch to the TestLibTests target and want to write my first test. Simply creating an object from the TestLib class. For that, I have to import the module, so I write 'import TestLib' after the 'import XCTest' at the top.
And here is where I'm stuck. No matter what I do, Xcode just gives me the error 'No such module TestLib'.
This should just work, right? I should be able to unit test my library. I have spent 2 days reading the internet and trying many suggestions, but I just can't get it to work.
I am currently working with Xcode 26 beta. But I tried with Xcode 16.4 and that has the same issue.
What am I missing?
                    
                  
                
                    
                      When I try to make a unit test target for my macOS app that uses Objective-C, running tests fails, and the debugging log shows a message "Creating more than one Application".  If, on the other hand, when I create the unit test target, I select "None" as the target to be tested, and then add all my sources to that target, my tests work.  So, I can get my testing done, but I think I must be doing something wrong.
By the way, along with the error message, there is a stack crawl:
	0   CoreFoundation                      0x00007ff8140410aa __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00007ff813b660b7 objc_exception_throw + 48
	2   Foundation                          0x00007ff814f19bd8 -[NSCalendarDate initWithCoder:] + 0
	3   AppKit                              0x00007ff817030062 -[NSApplication init] + 1718
	4   XCTestCore                          0x000000010774b0df -[XCTestDriver _createTestBundlePrincipalClassInstance] + 82
	5   XCTestCore                          0x0000000107749338 -[XCTestDriver _runTests] + 111
	6   XCTestCore                          0x000000010770f194 _XCTestMain + 126
	7   libXCTestBundleInject.dylib         0x0000000106e8982d __copy_helper_block_e8_32s + 0
	8   CoreFoundation                      0x00007ff813fc9a91 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
	9   CoreFoundation                      0x00007ff813fc99ca __CFRunLoopDoBlocks + 398
	10  CoreFoundation                      0x00007ff813fc883d __CFRunLoopRun + 898
	11  CoreFoundation                      0x00007ff813fc7e51 CFRunLoopRunSpecific + 560
	12  HIToolbox                           0x00007ff81da52f3d RunCurrentEventLoopInMode + 292
	13  HIToolbox                           0x00007ff81da52b84 ReceiveNextEventCommon + 199
	14  HIToolbox                           0x00007ff81da52aa8 _BlockUntilNextEventMatchingListInModeWithFilter + 64
	15  AppKit                              0x00007ff8170689d8 _DPSNextEvent + 858
	16  AppKit                              0x00007ff817067882 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1214
	17  AppKit                              0x00007ff817059ef7 -[NSApplication run] + 586
	18  AppKit                              0x00007ff81702e111 NSApplicationMain + 817
	19  PlainCalc                           0x00000001057d0a91 main + 65
	20  dyld                                0x00007ff813b93418 start + 1896
                    
                  
                
                    
                      After upgrading to Xcode 16.4, the navigation arrow icon in the Report Navigator is no longer appearing for failed test cases within XCResult bundles. This icon, which allows developers to directly navigate to the specific line of code that caused a test failure, is now missing. This significantly hinders the debugging process for test automation engineers.
Details:
Xcode Version: 16.4 (issue started after upgrade)
Test Framework: XCTest
Test Environment: iOS simulators
Execution Method: The tests are executed on a Jenkins CI/CD server
XCResult Analysis: The generated .xcresult bundle is downloaded from the Jenkins server and opened locally on a Mac also running Xcode 16.4.
Observed Behavior:
The navigation arrow icon is missing, and there is no direct way to jump to the failure line from the report.
This issue appears to be a regression introduced in Xcode 16.4, as the navigation arrow was consistently present in previous versions. Any insights or workarounds would be greatly appreciated.
                    
                  
                
                    
                      Hi, experts,
I want to find Siri response window by bundle id and use it for checking or printing, here is my example code:
XCUIDevice.shared.siriService.activate(voiceRecognitionText: "call mom")
let siriApp = XCUIApplication(bundleIdentifier: "***")
// Print out text from siriApp, 
// expecte print: "Sorry, I can't make a phone call with your iphone."
Where should I put into ***?
I tried "com.apple.SiriViewService", "com.apple.siri.velocity", "com.apple.springboard' but nothing work
Any suggestion appreciated, thanks!
                    
                  
                
                    
                      I have been learning from the Apple Developer tutorials and I got stuck on the ScoreKeeper chapter with Testing. Since my Macbook Pro 2017 can only use Xcode 15.2 as the highest level, I am having issues with it. I saw a forum post that a certain level of Swift and the tool chain would fix this. I attempted to install Swift 5.10.1 to then realize I only had Xcode 15.2 not 15.3, so I had to attempt to install Swift 5.9.  Since neither option worked, I uninstalled Xcode and removed any extra files along with swift packages, minus my projects, to redownload and reinstall Xcode 15.2.  Now I am having issues with building the scheme, and I get link error,s and they pertain to Swift 5.10.1, which I had not installed any Swift packages after the Xcode reinstallation. I have tried another previous project even a new one same error.  This was 7/30/25, as of today 7/31 I tried to install Swift 5.9 thinking it would overwrite or "downgrade" the package, no such luck.  The file path in the error stops at the /.../...RELEASE.pkg file and does not continue, which seems to be the issue of the error.   How to I fix this issue, I had a working product 3 dyas ago
                    
                  
                
                    
                      Hi,
we are using xctest UI tests integrated into a Jenkins CI pipeline. However, after upgrading the machine running automated tests to macOS Sequoia, we’re experiencing an issue: before each UI test, the system displays a popup asking for a password to allow XCTest to enable UI automation.
Is there any known workaround for this, please?
I’ve tried disabling SIP and modifying the TCC database, but nothing has worked so far.
Thank you in advance.
I’ve attached a screenshot of the popup.
                    
                  
                
                    
                      "UITests recording reports 'The capability "Create Service Socket" is not supported by this device.' on M1 chip, but works normally on Intel chip."