Hello!
I was faced with unexpected behavior of hardware keyboard focus in UITests.
A clear description of the problem
When running UITests on the iOS Simulator with both "Full Keyboard Access" and "Connect Hardware Keyboard" options enabled, there is a noticeable delay between keyboard actions for focus managing (like pressing Tab or arrow keys). The delay seems to increase with repeated input and suggests that events are being queued instead of processed immediately.
I will describe why I have such an assumption later.
A step-by-step set of instructions to reproduce the problem
Launch the iOS Simulator.
Enable both "Full Keyboard Access" and "Connect Hardware Keyboard" in the Simulator settings.
Run a UITest on a target application (ideally an endless or long-running test).
Once the app is launched, press the Tab key several times.
Observe the delay in focus movement.
Optionally, press the Tab or arrow keys rapidly, then stop the UITest.
After stopping, you’ll see a burst of rapid focus changes.
What results you expected
We expected keyboard actions (like Tab) to be handled immediately and the UI focus to update smoothly during UITests.
What results you saw
There was a 4–10 (end more) second delay between pressing keys and seeing a response. All stacked keyboard events (used for managing focus) are performed all at once after stopping the UITest.
The version of Xcode you are using
Xcode: Version 16.3 (16E140)
Simulator: iPhone 16 Pro (iOS 18.4 and 18.1)
Simulator: iPad Pro 11-inch (M4) (iPadOS 17.5)
XCTest
RSS for tagCreate and run unit tests, performance tests, and UI tests for your Xcode project using XCTest.
Posts under XCTest tag
71 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I'm using Xcode 14.3.1 on macOS 13.5, and I've managed to reproduce my issue in a trivial application. All the project settings are left at the defaults for a macOS project.
It looks like using a GroupBox breaks the ability of XCTest to find popovers connected to buttons (I suspect any UI element) inside the GroupBox.
The debug console output from the code below lists 15 descendants from my window with the outside-the-GroupBox popover open, and one of them is definitely a popover. With the inside-the-GroupBox popover open, my window only shows nine descendants, and no popover (the rest of the difference is the popover's contents). It's simple enough I don't see what I could be doing wrong:
import SwiftUI
@main
struct GroupBox_Popover_DemoApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
@State var outsidePopoverPresented: Bool = false
@State var insidePopoverPresented: Bool = false
var body: some View {
VStack {
Button("Outside GroupBox") {
outsidePopoverPresented = true
}
.popover(isPresented: $outsidePopoverPresented,
attachmentAnchor: .point(.leading),
arrowEdge: .leading) {
Popover(selected: .constant("Item A"), isPresented: $outsidePopoverPresented)
}
.padding()
GroupBox {
Button("Inside GroupBox") {
insidePopoverPresented = true
}
.popover(isPresented: $insidePopoverPresented,
attachmentAnchor: .point(.leading),
arrowEdge: .leading) {
Popover(selected: .constant("Item B"), isPresented: $insidePopoverPresented)
}
.padding()
}
}
.padding()
}
}
struct Popover: View {
@Binding var selected: String
@Binding var isPresented: Bool
var body: some View {
VStack(alignment: .leading) {
Picker("", selection: $selected) {
Text("Item A").tag("Item A")
Text("Item B").tag("Item B")
Text("Item C").tag("Item C")
}
.pickerStyle(.radioGroup)
HStack {
Spacer()
Button("Cancel") {
isPresented = false
}
}
}
.padding()
.frame(width: 200)
}
}
Then in my UI tests:
import XCTest
final class GroupBox_Popover_DemoUITests: XCTestCase {
let mainWindow = XCUIApplication().windows
override func setUpWithError() throws {
continueAfterFailure = false
XCUIApplication().launch()
}
func testPopovers() {
let myDescendants = mainWindow.descendants(matching: .any)
mainWindow.buttons["Outside GroupBox"].click()
print("Window descendants with outside popover open:")
print(myDescendants.debugDescription)
mainWindow.popovers.buttons["Cancel"].click()
mainWindow.buttons["Inside GroupBox"].click()
print("Window descendants with inside popover open:")
print(myDescendants.debugDescription)
mainWindow.popovers.buttons["Cancel"].click()
XCTAssert(true, "Test was able to hit cancel on both popovers.")
}
}
Any ideas? Have I missed unchecking some "Ignore anything in a GroupBox" checkbox somewhere?
Appium can't see any locators of 'Sandbox' view in case of purchase page automation try. iOS 18.x. On version 17.x the elements could be found
We are using XC Test case framework for the unit test cases after running test cases the code coverage is not visible. In previous version of Xcode it was working properly (like Xcode 15 and earlier).
Hello Apple Developer Support,
I am writing to seek assistance with an issue we are experiencing in our SwiftUI application concerning UI test cases.
Our application uses accessibility labels that differ slightly from the display content to enhance VoiceOver support. However, we have encountered a problem where our UI test cases fail when the accessibility label does not match the actual display content.
Currently, we are using accessibility identifiers in our tests, but they only retrieve the accessibility label, leaving us without a method to access the actual display content. This discrepancy is causing our automated tests to fail, as they cannot verify the visual content of the UI elements.
We would greatly appreciate any guidance or solutions you could provide to address this issue. Specifically, we are looking for a way to ensure our UI tests can access both the accessibility label and the actual display content for verification purposes.
For ex:
Problem scenario - setting accessibilityLabel masks access to any displayed content
If an accessibilityLabel is set on a UI element, then it seems to be no-longer possible to check/access the displayed content of that element:
var body: some View {
Text("AAA")
.accessibilityIdentifier("textThing")
.accessibilityLabel("ZZZ") // Different label from the text which is displayed in UI
}
// in test...
func test_ThingExists() {
XCTAssert(app.staticTexts["AAA"].exists) // Fails, cannot find the element
XCTAssertEqual(app.staticTexts["ZZZ"].label, "AAA") // Fails - '.label' is the accessibilityLabel, not the displayed content
XCTAssertEqual(app.staticTexts["ZZZ"].label, "ZZZ") // Passes, but validates the accessibility content, not the displayed content
XCTAssert(app.staticTexts["textThing"].exists) // Passes, but does not check the displayed content
XCTAssertEqual(app.staticTexts["textThing"].label, "AAA") // Fails - '.label' is the accessibilityLabel, not the displayed content
XCTAssertEqual(app.staticTexts["textThing"].label, "ZZZ") // Passes, but validates the accessibility content, not the displayed content
}
element.label still only checks the accessibilityLabel. There is not, it seems, an way back to being able to check the content of the Text element directly.
Thank you for your attention and support. We look forward to your valuable insights.
Xcode 16.1
iOS 18.1
iPad Air 13-inch (M2)
I have created a completely new Xcode project with Swift and Storyboard.
In Storyboard, I only have a tabBarController with two attached UIViewControllers.
The code from the base project hasn't been changed at all.
I created a UITest with a very simple premise.
let app = XCUIApplication()
override func setupWithError() throws {
continueAfterFailure = false
app.launch()
}
func testTabBarExistence() {
let tabBar = app.tabBars.element(boundBy: 0)
XCTAssertTrue(tabBar.waitForExistence(timeout: 5), "Tab bar should exist")
}
But this test always fails for iPad on iOS 18+, but it will succeed for anything lower (e.g. 17.5)
I am writing a SPM based project for MacOS. In this project? I need to access MacOS Keychain.
I am write a swift test built by SPM testTarget(). I can see it generates a bundle ./.build/x86_64-apple-macosx/debug/MyProjectTests.xctest with an executable:
% file ./.build/x86_64-apple-macosx/debug/MyProjectPackageTests.xctest/Contents/MacOS/MyProjectPackageTests
./.build/x86_64-apple-macosx/debug/MyProjectPackageTests.xctest/Contents/MacOS/MyProjectPackageTests: Mach-O 64-bit bundle x86_64
This bundle file cannot be executed. How can I execute its tests?
I tried with xcodebuild test-without-building -xctestrun ./.build/x86_64-apple-macosx/debug/MyProjectPackageTests.xctest -destination 'platform=macOS' without any chance.
Obviously the next question is can I 'simply' add entitlement to this bundle with codesign to fix my enttilement error.
My error when running the test is A required entitlement isn't present.
Dear Apple & Community,
I am encountering an issue while running my Unit tests on Xcode 16.
I'm receiving the following error in the debugger area.
Error loading /var/containers/Bundle/Application/FF057050-1BCC-49D8-9D3F-A3731E30F354/<Project_name>.app/PlugIns/<Project_name>.xctest/<Project_name>Tests (133): dlopen(/var/containers/Bundle/Application/FF057050-1BCC-49D8-9D3F-A3731E30F354/<Project_name>.app/PlugIns/<Project_name>.xctest/<Project_name>Tests, 0x0109): Symbol not found: _$s5Model11AccountDataV7TestingE4mockACvau
Referenced from: <4027FFAF-5C6C-3F8A-9862-648D3D4A1257> /private/var/containers/Bundle/Application/FF057050-1BCC-49D8-9D3F-A3731E30F354/<Project_name>.app/PlugIns/<Project_name>.xctest/<Project_name>Tests
Expected in: <406DF294-634D-3D8A-8E59-BEE455BA96AF> /System/Developer/Library/Frameworks/Testing.framework/Testing
Failed to load test bundle from file:///private/var/containers/Bundle/Application/FF057050-1BCC-49D8-9D3F-A3731E30F354/<Project_name>.app/PlugIns/<Project_name>.xctest/: Error Domain=NSCocoaErrorDomain Code=3588
.....
Hello Apple Developer Community,
I’m experiencing an issue with my iOS app, "WaterReminder," where it builds successfully in Xcode 16.2 but crashes immediately upon launch in the iPhone 16 Pro Simulator running iOS 18.3.1. The crash is accompanied by a "Thread 1: signal SIGABRT" error, and the Xcode console logs indicate a dyld error related to XCTest.framework/XCTest not being loaded. I’ve tried several troubleshooting steps, but the issue persists, and I’d appreciate any guidance or insights from the community.
Here are the details:
Environment:
Xcode Version: 16.2
Simulator: iPhone 16 Pro, iOS 18.3.1
App: WaterReminder (written in SwiftUI 6)
Build Configuration: Debug
Issue Description:
The app builds without errors, but when I run it in the iPhone 16 Pro Simulator, it shows a white screen and crashes with a SIGABRT signal. The Xcode debugger highlights the issue in the main function or app delegate, and the console logs show the following error:
dyld[7358]: Library not loaded: @rpath/XCTest.framework/XCTest
Referenced from: <549B4D71-6B6A-314B-86BE-95035926310E> /Users/faytek/Library/Developer/CoreSimulator/Devices/2A51383F-D8EA-4750-AE22-4CDE745164CE/data/Containers/Bundle/Application/56D8B44F-6613-4756-89F0-CB33991F0821/WaterReminder.app/WaterReminder.debug.dylib
Reason: tried: '/Users/faytek/Library/Developer/Xcode/DerivedData/WaterReminder-cahqrulxghamvyclxaozotzrbsiz/Build/Products/Debug-iphonesimulator/XCTest.framework/XCTest' (no such file), '/Users/faytek/Library/Developer/CoreSimulator/Devices/2A51383F-D8EA-4750-AE22-4CDE745164CE/data/Containers/Bundle/Application/56D8B44F-6613-4756-89F0-CB33991F0821/WaterReminder.app/Frameworks/XCTest.framework/XCTest' (no such file), '/Users/faytek/Library/Developer/CoreSimulator/Devices/2A51383F-D8EA-4750-AE22-4CDE745164CE/data/Containers/Bundle/Application/56D8B44F-6613-4756-89F0-CB33991F0821/WaterReminder.app/XCTest.framework/XCTest' (no such file), '/Users/faytek/Library/Developer/CoreSimulator/Devices/2A51383F-D8EA-4750-AE22-4CDE745164CE/data/Containers/Bundle/Application/56D8B44F-6613-4756-89F0-CB33991F0821/WaterReminder.app/Frameworks/XCTest.framework/XCTest' (no such file), '/Users/faytek/Library/Developer/CoreSimulator/Devices/2A51383F-D8EA-4750-AE22-4CDE745164CE/data/Containers/Bundle/Application/56D8B44F-6613-4756-89F0-CB33991F0821/WaterReminder.app/XCTest.framework/XCTest' (no such file), '/Users/faytek/Library/Developer/CoreSimulator/Devices/2A51383F-D8EA-4750-AE22-4CDE745164CE/data/Containers/Bundle/Application/56D8B44F-6613-4756-89F0-CB33991F0821/WaterReminder.app/Frameworks/XCTest.framework/XCTest' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_22D8075/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.3.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/XCTest.framework/XCTest' (no such file)
What I’ve Tried:
◦ Verified that FBSnapshotTestCase is correctly added to the "Embed Frameworks" build phase.
◦ Confirmed that the Framework Search Paths in build settings point to the correct location.
◦ Ensured that all required frameworks are available in the dependencies folder.
◦ Cleaned the build folder (Shift + Option + Command + K) and rebuilt the project.
◦ Checked the target configuration to ensure XCTest.framework isn’t incorrectly linked to the main app target (it’s only in test targets).
◦ Updated Xcode and the iOS Simulator to the latest versions.
◦ Reset the simulator content and settings.
Despite these steps, the app continues to crash with the same dyld error and SIGABRT signal. I suspect there might be an issue with how XCTest.framework is being referenced or loaded in the simulator, possibly related to using SwiftUI 6, but I’m unsure how to resolve it.
Could anyone provide advice on why XCTest.framework is being referenced in my main app (since it’s not intentionally linked there) or suggest additional troubleshooting steps? I’d also appreciate any known issues or workarounds specific to Xcode 16.2, iOS 18.3.1, and SwiftUI 6.
Thank you in advance for your help!
Best regards,
Faycel
I am trying to test this simulated Error.
The issue is, I can't get this to trigger through the simulatedError function.
Error will always end up as an unknown error
Example code snippet:
@available(iOS 17.0, *)
func testPurchase_InvalidQuantity() async throws {
// Arrange
testSession.clearTransactions()
testSession.resetToDefaultState()
let productID = "consumable_1"
try await testSession.setSimulatedError(.purchase(.invalidQuantity), forAPI: .purchase)
guard let product = await fetchProduct(identifier: productID) else {
XCTFail("Failed to fetch test product")
return
}
let option = Product.PurchaseOption.quantity(4)
let result = await manager.purchase(product: product, options: option)
switch result {
case .success:
XCTFail("Expected failure due to invalid quantity")
case .failure(let error):
print("Received error: \(error.localizedDescription)")
switch error {
case .purchaseError(let purchaseError):
XCTAssertEqual(purchaseError.code, StoreKitPurchaseError.invalidQuantity.code)
default:
XCTFail("Unexpected error: \(error)")
}
}
}
In the above code snippet, I have an Unexpected Error.
But if i remove try await testSession.setSimulatedError(.purchase(.invalidQuantity), forAPI: .purchase) I will receive a XCTFail in the success of my result.
So when I set the quantity to a -1, only then can I correctly receive an invalidQuantity.
Does anyone know why the try await testSession.setSimulatedError(.purchase(.invalidQuantity), forAPI: .purchase) would fail to work as directed? I have tests for all the generic errors for loadProducts API and the simulatedError works great for them
We are getting unreliable results on XCode Cloud tests. I'm not sure if it's related to the current service outage.
I'm running a very simple XCTest UI suite, on some devices it succeds and it others it fails to start. I'm not getting a userful error message.
MyApp-Runner encountered an error (Failed to prepare device 'iPhone 16 Pro Max' for impending launch. (Underlying Error: Unable to boot the Simulator. launchd failed to respond. (Underlying Error: Failed to start launchd_sim: could not bind to session, launchd_sim may have crashed or quit responding)))
For my app I've created a Dictionary that I want to persist using AppStorage
In order to be able to do this, I added RawRepresentable conformance for my specific type of Dictionary. (see code below)
typealias ScriptPickers = [Language: Bool]
extension ScriptPickers: @retroactive RawRepresentable where Key == Language, Value == Bool {
public init?(rawValue: String) {
guard let data = rawValue.data(using: .utf8),
let result = try? JSONDecoder().decode(ScriptPickers.self, from: data)
else {
return nil
}
self = result
}
public var rawValue: String {
guard let data = try? JSONEncoder().encode(self), // data is Data type
let result = String(data: data, encoding: .utf8) // coerce NSData to String
else {
return "{}" // empty Dictionary represented as String
}
return result
}
}
public enum Language: String, Codable, {
case en = "en"
case fr = "fr"
case ja = "ja"
case ko = "ko"
case hr = "hr"
case de = "de"
}
This all works fine in my app, however trying to run any tests, the build fails with the following:
Conflicting conformance of 'Dictionary<Key, Value>' to protocol 'RawRepresentable'; there cannot be more than one conformance, even with different conditional bounds
But then when I comment out my RawRepresentable implementation, I get the following error when attempting to run tests:
Value of type 'ScriptPickers' (aka 'Dictionary<Language, Bool>') has no member 'rawValue'
I hope Joseph Heller is out there somewhere chuckling at my predicament
any/all ideas greatly appreciated
I'm working on Apple Watch UI tests and have noticed different results between local and Xcode Cloud environments.
I tested all cases locally, and they worked fine. However, when running the tests on Xcode Cloud, some issues caused them to fail:
The test requires clicking a button to display the built-in keyboard, but on Xcode Cloud, the keyboard never appears, no matter how long I wait.
The app unexpectedly closes during testing, displaying the error message: "Failed to launch application {Your app} is not running."
These failures occurred on two different simulator destinations (Ultra 49mm 11.2 / Series 7 45mm 11.2) and can only be reproduced on specific simulators.
Has anyone encountered a similar issue?
Hi,
Overview
I am using Xcode Cloud for my multi platform app.
The macOS test case fails, however the iOS test case runs and succeeds.
I don't have any UI test cases written, the test case are simple and have nothing platform (macOS) specific.
Questions
What can I do to fix this?
Is there any user privileges needed to launch the macOS app for testing? I ask because when I ran the UI tests locally it launched the app and asked for my macOS user password. Just wondering if that is the reason it didn't launch in Xcode Cloud.
Error:
<Appname> encountered an error (Failed to install or launch the test runner. If you believe this error represents a bug, please attach the result bundle at /Volumes/workspace/resultbundle.xcresult.(Underlying Error: Could not launch "AppnameTests. The LaunchServices launcher has returned an error. Please check the system logs for
the underlying cause of the error. (Underlying Error: The operation couldn't be completed. Launch failed. (Underlying Error: Launch job spawn failed) )))
× Could not launch "<Appname>"
× Could not launch "AppnameTests"
× AppnameUITests.testExample()
Failed to get launch progress for <XCUIApplicationImpl: 0x600000564630 <BundleID> at /Volumes/workspace/TestProducts/Debug-Dev/<Appname>.app>: Could not launch "app name". The LaunchServices launcher has returned an error. Please check the system logs for the underlying cause of the error. (Underlying Error: The operation couldn't be completed. Launch failed. (Underlying Error: Launch job spawn failed))
AppnameUITests.swift:28
* AppnameUITests.testLaunchPerformance)
Failed to get launch progress for «XCUIApplicationimpl: 0x60000054630 <BundleID> at /Volumes/workspace/TestProducts/Debug-Dev/<Appname>.apps: Could not launch "<Appname>". The LaunchServices launcher has returned an error. Please check the system logs for the underlying cause of the error. (Underlying Error: The operation couldn't be completed. Launch failed. (Underlying Error: Launch job spawn failed))
AppnameUITests.swift:37 g
* AppnameUITestsLaunchTests.testLaunch)
Failed to get launch progress for «XCUIApplicationimpl: 0x60000054630 <BundleID> at /Volumes/workspace/Testroducts/Debug-Dev/<Appname>.apps: Could not launch "<Appname>". The LaunchServices launcher has returned an error. Please check the system logs for the underlying cause of the error. (Underlying Error: The operation couldn't be completed. Launch failed.
I'd like to set up a communication mechanism between the Ui test runner and my iOS app. The purpose is to be able to collect some custom performance metrics in addition to standard ones like scrollingAndDecelerationMetric. Let's say we measure some specific intervals in our code using signposts, then serialize the result into a structured payload and report it back to the runner.
So, are there any good options for that kind of IPC?
The primary concern is running on Simulator. However, since it is not a regular UI test but more a performance UI test, and it is usually recommended to run those on a real device, with release optimizations/flags in place, I wonder if it is feasible to have it for device too.
As SwiftUI adoption grows, developers face challenges in effectively measuring and optimizing SwiftUI app performance within automated tests.
Currently, the only viable approach to analyzing SwiftUI performance is through Profiling (Instruments), which, while powerful, lacks the ability to be incorporated into automated testing workflows. It would be incredibly valuable if XCTest could introduce new performance metrics specifically tailored for SwiftUI, allowing us to write tests against common performance bottlenecks.
Suggested Metrics:
View Body Evaluation Count – Tracks how often a SwiftUI body is recomputed to detect unnecessary re-renders.
Slow View Bodies – Flags SwiftUI views that take a significant amount of time to compute their body.
These metrics would help developers identify inefficiencies early, enforce performance best practices through CI/CD pipelines, and ensure a smooth user experience. I believe adding these performance metrics would be a game-changer for SwiftUI development.
Thank you for your time and consideration!
I'm trying to use Xcode UI tests for the first time. I added a UI Tests target and set up the signing, then opened the default AppnameUITests.swift file. I added a new function named testAboutPage(), clicked inside the block and clicked the Record UI Test button (red circle) at the bottom of the editor window. If the app is already running when I do this, Xcode crashes immediately. If the app is not running, Xcode builds and runs the app, then crashes.
I've seen reports of this going back years, but none of the posts have a solution. I do have a crash log to share. Does anyone know how to get past this?
This forum won't let me upload the complete crash log because it exceeds the size limit, but here's the first part through the stack trace of the crashed thread:
Process: Xcode [46652]
Path: /Applications/Xcode.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 16.2 (23507)
Build Info: IDEApplication-23507000000000000~2 (16C5032a)
App Item ID: 497799835
App External ID: 870964517
Code Type: ARM-64 (Native)
Parent Process: launchd [1]
User ID: 503
Date/Time: 2025-02-04 12:58:05.5200 -0800
OS Version: macOS 15.3 (24D60)
Report Version: 12
Anonymous UUID: 144B0B99-8D44-736B-0D9A-1F6FA6DF85F7
Time Awake Since Boot: 48000 seconds
System Integrity Protection: enabled
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Termination Reason: Namespace SIGNAL, Code 6 Abort trap: 6
Terminating Process: Xcode [46652]
Application Specific Information:
abort() called
Application Specific Signatures:
((result)) != nil
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x18a3b3720 __pthread_kill + 8
1 libsystem_pthread.dylib 0x18a3ebf70 pthread_kill + 288
2 libsystem_c.dylib 0x18a2f8908 abort + 128
3 IDEKit 0x109e81554 +[IDEAssertionHandler _handleAssertionWithLogString:assertionSignature:assertionReason:extraBacktrace:] + 964
4 IDEKit 0x109e819e4 -[IDEAssertionHandler handleFailureInMethod:object:fileName:lineNumber:assertionSignature:messageFormat:arguments:] + 876
5 DVTFoundation 0x10600d358 _DVTAssertionHandler + 424
6 DVTFoundation 0x10600d4d8 _DVTAssertionFailureHandler + 196
7 IDEKit 0x10a1f99e4 -[IDEUIRecordingManager _workspaceTabController] + 176
8 IDEKit 0x10a1fa528 __94-[IDEUIRecordingManager _startRecordingWithLaunchSession:alwaysAskForAPIAccess:reservedNames:]_block_invoke_3 + 252
9 DVTFoundation 0x10611fc9c __DVT_CALLING_CLIENT_BLOCK__ + 16
10 DVTFoundation 0x1061206c4 __DVTDispatchAsync_block_invoke + 152
11 libdispatch.dylib 0x18a237854 _dispatch_call_block_and_release + 32
12 libdispatch.dylib 0x18a2395b4 _dispatch_client_callout + 20
13 libdispatch.dylib 0x18a248040 _dispatch_main_queue_drain + 984
14 libdispatch.dylib 0x18a247c58 _dispatch_main_queue_callback_4CF + 44
15 CoreFoundation 0x18a5139d0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
16 CoreFoundation 0x18a4d35bc __CFRunLoopRun + 1996
17 CoreFoundation 0x18a4d2734 CFRunLoopRunSpecific + 588
18 HIToolbox 0x195a41530 RunCurrentEventLoopInMode + 292
19 HIToolbox 0x195a47348 ReceiveNextEventCommon + 676
20 HIToolbox 0x195a47508 _BlockUntilNextEventMatchingListInModeWithFilter + 76
21 AppKit 0x18e04a848 _DPSNextEvent + 660
22 AppKit 0x18e9b0c24 -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 688
23 AppKit 0x18e03d874 -[NSApplication run] + 480
24 IDEKit 0x109e50f14 -[IDEApplication run] + 192
25 AppKit 0x18e014068 NSApplicationMain + 888
26 dyld 0x18a06c274 start + 2840
I'd like to implement unit tests that exercise keys made available via a persistent token interface. However, when attempting to list available tokens by passing kSecAttrAccessGroupToken as the kSecAttrAccessGroup to SecItemCopyMatching from a unit test, -34018 is returned. It succeeds without the kSecAttrAccessGroup, which makes sense given the unit test binary does not have com.apple.token Keychain Group. The Xcode UI indicates "Capabilities are not supported" for the unit test binary when attempting to add a Keychain Sharing capability to enable use of persistent tokens. This feels like a dead end but begs the question is there any way to implement unit tests to exercise a persistent token interface? It seems like the only path may be write unit tests that drive an independent app that handles the interactions with the persistent token.
Hi,
I am working on an agent app.
The app has a menubarextra.
var body: some Scene {
MenuBarExtra(
"menubarextra", systemImage: "star")
{
Button("Item 1") {
}
Button("Item 2") {
}
Button("Item 3") {
}
}
}
I am going to write xctest to click on the icon i created and want to click on the menu next.
func testExample() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()
let menuBarsQuery = XCUIApplication().menuBars
let favouriteStatusItem = menuBarsQuery.statusItems["Favourite"]
favouriteStatusItem.click()
menuBarsQuery.menuItems["Item 1"].click()
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
There is a small problem. When the app is not a agent app, the app will start with with its own menu bar. If i am currently on fullscreen, it will swap to the desktop and the menubar will be showing the app's menu bar. In this case, I can see the menubarextra. The test will pass then.
When it is in agent app, the above behaviour will not happen. Once I run the test with fullscreen mode of xcode, my screen will still stay on xcode and the statusbar will not be showing. Then the test will response
error: -[swiftuitestUITests.MenubarExtraTests testExample] : Element StatusItem, {{1080.0, 6.5}, {34.5, 24.0}}, title: 'Favourite' is not hittable
The only solution I can found at the moment is to leave fullscreen first, then run the test.
In xctest, is there any way to force the statusbar to show first?
Thank you!
I'm developing a library and using XCTest for unit tests. While trying to profile the test suite, I noticed that Instruments seems to report a leak every single time the async throwing setup function is called, no matter what.
For example,
This will report a leak:
final class LeakTests: XCTestCase {
override func setUp() async throws {
try await super.setUp()
}
func testLeak() async throws {
try await Task.sleep(nanoseconds: 5_000_000_000)
}
}
This will not report a leak:
final class LeakTests: XCTestCase {
// override func setUp() async throws {
// try await super.setUp()
// }
func testLeak() async throws {
try await Task.sleep(nanoseconds: 5_000_000_000)
}
}
Any ideas on why this might be happening, or should I just file a bug report? It makes it quite difficult to use the leak detection for unit tests, as it shows hundreds of leaks when the whole suite is ran.