Create and run unit tests, performance tests, and UI tests for your Xcode project using XCTest.

Posts under XCTest tag

98 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

HideAllTips launch argument does not work in xctestplan
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.
1
0
33
1d
Dynamic Library and Unit Testing - Module not found
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?
0
0
324
1w
Xcode unit test "Creating more than one Application"
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
3
0
103
1w
Report Navigator Arrow Icon Missing in XCResult Files Since Xcode 16.4
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.
1
1
48
2w
How to find Siri response window by bundle id
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!
1
0
39
3w
linking error file cannot be open()ed, errno=2
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
2
0
82
Aug ’25
XCTest UI Tests Trigger Password Prompt on macOS Sequoia – How to Disable in CI?
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.
1
0
107
Jul ’25
code coverage broken 0% since Xcode 16.2
Hi, moving from Xcode 16.1 to 16.2, the code coverage percentage is still 0. The project is quite old, but it worked with 16.1. What I tried: converted the old tests to test plans in the settings, including all the various targets (for internal functionality contained in frameworks, each framework has its own test target). added the various code coverage flags to YES. added test hosts to the main targets. played with various settings found in dozens of guides. But nothing. The main app shows 0% coverage, even though the internal frameworks have their own coverage and the files within the main app are tested. On Xcode 16.1, the % appears, but from 16.2 onwards, it doesn't. Also tried with Xcode 26. Any ideas? Thanks
0
2
135
Jul ’25
UI Automation not waiting on WatchOS?
On my MacBook Pro M4 with macOS 15.5 and Xcode 16.4, I have a simple SwiftUI-based WatchOS application consisting of a NavigationSplitView that displays a short List of items, and a detail view consisting of a TabView {...}.tabViewStyle(.verticalPage) that displays a fixed number of "pages" of detailed information about the selected list item. When I use XCTest UI Automation with XCUIApplication(), I am finding that I need to add a sleep(1) after every interaction, such as a .tap() or .swipeUp() before I can attempt any assertion such as XCTAssertGreaterThan(app.cells.count, 3) to ensure that the top level List of items is more than 3. All the added sleep(1) statements are making the tests very slow... It appears that the WatchOS implementation of UI Automation lacks the ability to wait until the UI event queue is idle. Am I the only one seeing this?
0
0
69
Jun ’25
Authentication in UI tests
Hello! I am writing UI tests for an app with OAuth authentication and want to avoid the login screen. I want each developer to store the password and username locally on their machines. The bash script will get the token. I need to access that token from my test target somehow. The idea was to write them to a temporary file that git ignores and access this file from the bundle. But I can't add the file from the build script to the target and make it accessible from the code.
0
0
64
Jun ’25
SwiftMacros Not able to access of main project XCTest File.
I have developed a Swift macro called @CodableInit in the SwiftCodableMacro module, and I’m able to use it successfully in my main project. Here’s an example usage: import SwiftCodableMacro @CodableInit // This is for Codable macros public class ErrorMonitoringWebPlugin { public var identifier: UUID = UUID() // MARK: - Codable required public init(from decoder:Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self) identifier = try values.decode(UUID.self, forKey: .identifier) } } However, when I try to write a unit test for the ErrorMonitoringWebPlugin class, I encounter an issue. Here's the test case: func testCodableSubjectIdentifierShouldEqualDecodedSubjectIdentifier() { self.measure { let encoder = JSONEncoder() let data = try? encoder.encode(subject) //Here I am getting this error Class 'JSONEncoder' requires that 'ErrorMonitoringWebPlugin' conform to 'Encodable' let decoder = JSONDecoder() let decodedSubject = try? decoder.decode(ErrorMonitoringWebPlugin.self, from: data!) XCTAssertEqual(subject.identifier, decodedSubject?.identifier) } } The compiler throws an error saying: Class 'JSONEncoder' requires that 'ErrorMonitoringWebPlugin' conform to 'Encodable' Even though the @CodableInit macro is supposed to generate conformance, it seems that this macro-generated code is not visible or active inside the test target. How can I ensure that the @CodableInit macro (from SwiftCodableMacro) is correctly applied and recognized within the XCTest target of my main project?
0
0
43
Jun ’25
Autogenerated UI Test Runner Blocked By Local Network Permission Prompt
I've recently updated one of our CI mac mini's to Sequoia in preparation for the transition to Tahoe later this year. Most things seemed to work just fine, however I see this dialog whenever the UI Tests try to run. This application BoostBrowerUITest-Runner is auto-generated by Xcode to launch your application and then run your UI Tests. We do not have any control over it, which is why this is most surprising. I've checked the codesigning identity with codesign -d -vvvv as well as looked at it's Info.plist and indeed the usage descriptions for everything are present (again, this is autogenerated, so I'm not surprised, but just wanted to confirm the string from the dialog was coming from this app) <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>BuildMachineOSBuild</key> <string>22A380021</string> <key>CFBundleAllowMixedLocalizations</key> <true/> <key>CFBundleDevelopmentRegion</key> <string>en</string> <key>CFBundleExecutable</key> <string>BoostBrowserUITests-Runner</string> <key>CFBundleIdentifier</key> <string>company.thebrowser.Browser2UITests.xctrunner</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundleName</key> <string>BoostBrowserUITests-Runner</string> <key>CFBundlePackageType</key> <string>APPL</string> <key>CFBundleShortVersionString</key> <string>1.0</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleSupportedPlatforms</key> <array> <string>MacOSX</string> </array> <key>CFBundleVersion</key> <string>1</string> <key>DTCompiler</key> <string>com.apple.compilers.llvm.clang.1_0</string> <key>DTPlatformBuild</key> <string>24A324</string> <key>DTPlatformName</key> <string>macosx</string> <key>DTPlatformVersion</key> <string>15.0</string> <key>DTSDKBuild</key> <string>24A324</string> <key>DTSDKName</key> <string>macosx15.0.internal</string> <key>DTXcode</key> <string>1620</string> <key>DTXcodeBuild</key> <string>16C5031c</string> <key>LSBackgroundOnly</key> <true/> <key>LSMinimumSystemVersion</key> <string>13.0</string> <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict> <key>NSAppleEventsUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSBluetoothAlwaysUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSCalendarsUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSCameraUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSContactsUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSDesktopFolderUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSDocumentsFolderUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSDownloadsFolderUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSFileProviderDomainUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSFileProviderPresenceUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSLocalNetworkUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSLocationUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSMicrophoneUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSMotionUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSNetworkVolumesUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSPhotoLibraryUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSRemindersUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSRemovableVolumesUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSSpeechRecognitionUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSSystemAdministrationUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>NSSystemExtensionUsageDescription</key> <string>Access is necessary for automated testing.</string> <key>OSBundleUsageDescription</key> <string>Access is necessary for automated testing.</string> </dict> </plist> Additionally, spctl --assess --type execute BoostBrowserUITests-Runner.app return an exit code of 0 so I assume that means it can launch just fine, and applications are allowed to be run from "anywhere" in System Settings. I've found the XCUIProtectedResource.localNetwork value, but it seems to only be accessible on iOS for some reason (FB17829325). I'm trying to figure out why this is happening on this machine so I can either fix our code or fix the machine. I have an Apple script that will allow it, but it's fiddly and I'd prefer to fix this the correct way either with the machine or with fixing our testing code.
9
1
286
Jun ’25
XCUITests not starting
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
0
0
89
Jun ’25
The UT coverage does not include branch coverage for swift
We using below command to run unit test and collect coverage: xcodebuild -workspace Demo.xcworkspace -scheme VideoTests -configuration Debug -derivedDataPath ../build/derivedData -destination 'platform=iOS Simulator,id=E6630007-570B-4DEB-A023-2BCE91116A8D' -resultBundlePath './fastlane/test_output/VideoTests.xcresult' -enableCodeCoverage YES -testPlan 'Video' test-without-building | tee '/Users/rcadmin/Library/Logs/scan/VideoTests.log' | xcbeautify -q --is-ci and using xcrun llvm-cov show command to generate coverage report: xcrun llvm-cov show /build/unit-test/coverage/libraries/merged/video.o -instr-profile=/app/ios/build/derivedData/Build//ProfileData/E6630007-570B-4DEB-A023-2BCE91116A8D/video.profdata -show-branches count -show-expansions -show-line-counts -use-color -format=html -output-dir coverage and the html report does not include branch coverage: how to generate the branch coverage?
0
0
94
May ’25
Xcode Not Displaying Code Coverage for Main App When Using Test Plan on iOS Simulator
I am encountering an issue where code coverage data is not showing for my main app in Xcode when running tests for the iOS simulator. However, code coverage is being reported correctly for some modules. Enable Code Coverage Support: YES Xcode 16.2 macOS: 15.3.1 Macbook Pro M1 14-inch, 2021 Despite these configurations, Xcode fails to show code coverage for the main app. Can anyone suggest what might be causing this issue and how to ensure code coverage is correctly reported for the main app during simulator builds?
1
0
134
May ’25
run XCUITest with an SKStoreReviewController
I'm building out a number of XCUITests. At one stage in my app, we present an SKStoreReviewController to ask the user if they'd like to review the app now. All I'd like to do is dismiss the view, by hitting the "Not Now" button. Normally, for other "system" views, I'd something like this: let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") let notNowButton = springboard.buttons["Not Now"] And then I'd do an appropriate 'wait' and tap action. But for some reason, this isn't working. Looking for advice on how to properly handle this screen.
2
0
87
Jun ’25
Tabbar UITest bug on tvOS
When running UITests on tvOS, tabBar viewIdentifiers (UIKit) are no longer appearing. When you run the test, accessibility identifiers for tabs are no longer locatable but all other identifiers appears except for the tabs in the tabBar. In the stack trace of the debugger, if I print application, I can see all existing viewIdentifiers except those that were set for the tabs (on tvOS only). If I force an action on the simulator after the app has launched and the view appeared ie move left or right, the identifiers appears (confirmed by stack trace) and the test will continue as expected. This was not an issue in the past (no code changes). I am not sure if this appeared after updating my mac to Sequoia. But for iOS, there is no issue. This bug only appears on tvOS and specifically the tabs. Issue persists on: Sequoia 15.4.1 Xcode 16.3
1
0
60
May ’25
Unexpected behaviour of hardware keyboard focus in UITests
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)
1
2
121
Apr ’25