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

Posts under XCTest tag

145 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Help with SKTestSession Setup - ASDErrorDomain Code 505 Error
Hello everyone, I’m having trouble configuring SKTestSession for StoreKit testing in my UI tests. Specifically, I’m encountering the ASDErrorDomain Code 505 error when trying to set the storefront and locale in my test configuration. Despite following the setup steps, I keep getting errors indicating that the storefront and locale cannot be set, and the transactions are not being processed correctly. Here are the error messages I’m seeing: [SKTestSession] Error saving configuration file: Error Domain=ASDErrorDomain Code=505 "(null)" [SKTestSession] Error setting storefront to JPN for com.company.product: Error Domain=ASDErrorDomain Code=505 "(null)" [SKTestSession] Error fetching the current storefront: Error Domain=ASDErrorDomain Code=505 "(null)" [SKTestSession] Error setting value to ja for identifier 4 for com.company.product: Error Domain=ASDErrorDomain Code=505 "(null)" [SKTestSession] Error fetching value for identifier 4 for com.company.product: Error Domain=ASDErrorDomain Code=505 "(null)" These errors suggest that SKTestSession is unable to save or apply the configuration properly, but I’m not sure why. I’ve tried various storefronts and locales, but the issue persists. I’m running this on Xcode 16.0 (16A242d) on macOS 14.7 and 15. Below is the code for the setUpSession function I’m using to configure the session: func setUpSession(configuration: String = "Configuration", storefront: String? = nil, localeIdentifier: String? = nil) throws -> SKTestSession { var session: SKTestSession! try XCTContext.runActivity(named: "Set up subscriptions for \"\(configuration)\" storefront: \"\(storefront ?? "")\" and locale: \"\(localeIdentifier ?? "")\"") { activity in session = try SKTestSession(configurationFileNamed: configuration) if let storefront { session.storefront = storefront } if let localeIdentifier { session.locale = Locale(identifier: localeIdentifier) } session.disableDialogs = true let info = XCTAttachment(string: "storefront: \(session.storefront)\nlocale: \(session.locale.identifier)\ntransactions: \(session.allTransactions().count)") info.name = "Session configuration" activity.add(info) XCTAssertEqual(session.storefront, storefront, "Failed to set storefront") XCTAssertEqual(session.locale.identifier, localeIdentifier, "Failed to set locale") } return session } What I’ve Tried: Ensuring that storefront and locale values are valid. Resetting StoreKit configuration in Xcode’s scheme settings. Deleting derived data and restarting Xcode. Testing with different values for storefront and locale. Has anyone encountered similar issues with ASDErrorDomain Code 505, or can anyone point out what might be causing this? Any help would be greatly appreciated! Thank you!
0
3
310
Oct ’24
Xcode not generating code coverage.
No coverage is generated for private xxxx.framework, but tests are running under this framework. This was perfectly working before and started giving this error after updating to Xcode 16. Failed to generate coverage for target xxxx.framework at paths ( "/Users/xxxxxx/Desktop/xcode/Debug-iphonesimulator/Common/xxxxxx.framework/xxxx" ): No object file for requested architecture The operation couldn’t be completed. (XCTHCoverageReportGenerationErrorDomain error 2.). (Underlying Error: No object file for requested architecture)
1
0
249
2w
XCUITest target invalid config sets both USES_XCTRUNNER and either TEST_HOST or RUNTIME_TEST_HOST
I am trying to add an XCUITest target to an existing application. When I try to run the tests, I get the error "Invalid configuration: MyProjectUITests sets both USES_XCTRUNNER and either TEST_HOST or RUNTIME_TEST_HOST". I have seen information stating that it might be because I have multiple apps built from different build configurations in the same scheme, but I could not resolve the issue with any of the suggestions I saw. I've attached a screenshot of the error message and a link to a project stripped down to just the existing configuration to help with diagnosing this issue. I would really love to be able to get some UI tests running. My Project
1
0
230
2w
Bonjour not working with UI Test Target
I am trying to browse an SSH Service from UI Test Target using NWBrowser let descriptor = NWBrowser.Descriptor.bonjour(type: "_superapp._tcp", domain: "local.") let browser = NWBrowser(for: descriptor, using: .tcp) browser.stateUpdateHandler = { newState in print("browser.stateUpdateHandler \(newState)") } I get failed(-65555: NoAuth) error nw_browser_fail_on_dns_error_locked [B1] DNSServiceBrowse failed: NoAuth(-65555) I have added _superapp._tcp in Bonjour Services for UI Test Target Info.plist. I have also added Local Network Permission in UI Test Target Info.plist. Everything works fine, when I call this Bonjour service from App Target. Doesn't work when I call this from UI Test Target.
3
0
298
Oct ’24
Not able to inspect react native drop down element in iOS
Am trying to automate below drop down but iOS Accessibility inspector is unable to detect the element. Even we tried with Appium Inspector issue is same. Drop down: https://www.npmjs.com/package/react-native-element-dropdown We tried to debug the dropdown component. In that we can see the value is rendered properly from react. We have raised the issue with Appium, but they have given few suggestions in the Appium setting but it didn't solve. Now it's something that has to be done from XCTest Framework end. Appium issue git link: https://github.com/appium/appium/issues/14825
0
0
148
Sep ’24
Running local package's tests in main app's test plan
Hi, I work on a iOS application which includes several local swift packages containing modularised code. Each of those local swift packages has a test target defined in their respective Package.swift, and when opening a local package folder standalone in Xcode, then the tests run without issues. However I would like in the main app's test plan to add the local package test targets and have them all run together when the main app's default test plan is run. Xcode allows me to select local package test targets within the main app's test plan (also within Test portion of the main app's scheme), however attempting to build for testing throws a "Module '…' was not compiled for testing". Any ideas on how to achieve this goal (run local package tests in conjunction with main app's tests) and avoid that error? Thanks Peter
0
3
276
Sep ’24
Xcode 16 | xcodebuild fails when providing -destination 'platform=iOS Simulator,name=iPhone 16,arch=x86_64'
Hello. In the Xcode 15 we were using this command in the terminal to run our tests on the Rosetta Simulator: xcodebuild -workspace CoreLibraries.xcworkspace -scheme CoreLibraries -destination 'platform=iOS Simulator,name=iPhone 15,arch=x86_64' test` In the Xcode 16 the same command doesn't work anymore. It produces the error: xcodebuild: error: Unable to find a device matching the provided destination specifier: { platform:iOS Simulator, arch:x86_64, OS:latest, name:iPhone 16 } Unsupported device specifier option. The device “iPhone 16” does not support the following options: arch Please supply only supported device specifier options. Running test directly from the Xcode UI using iPhone 16 (Rosetta) still works fine. Does anyone know how to modify the xcodebuild command to make it work again?
12
9
1.7k
Oct ’24
How do I query the "+" button in XCTest?
I have a + image in the UI from the following code struct QueryPlusButton: View { var body: some View { Button { } label: { Image(systemName: "plus") } } } However, I'm not able to query the + image in XCTest using any of the following queries let view = app.images["plus"] //let view = app.staticTexts["plus"] //let view = app.buttons["plus"] XCTAssertTrue(view.exists, "Plus button does not exist") The test fails. Is there a methodical way to determine what a query is for any UI element? Thank you.
1
0
227
Sep ’24
Mocking or simulating CBPeripheral, CBCentralManager, etc in tests
I am developing an app that uses CoreBluetooth to communicate with a proprietary piece of hardware. I would like to be able to write tests for it, but there does not seem to be any way to mock or simulate the presence of, for example a CBPeripheral object. This library (https://github.com/NordicSemiconductor/IOS-CoreBluetooth-Mock) almost does what I need, but it's not quite flexible enough. I think they have the right idea, but it doesn't seem to be actively maintained anymore. This seems like a pretty big hole in the iOS SDK. Is there really not an officially supported way of testing BLE functionality?
3
0
375
Sep ’24
Do I need to down load iOS 18 for testing on iPhone 11 having iOS version 17.6.1 ?
I am using two iPhone11 devices, having iOS v17.6.1 for automation testing using Seleniumv4.X-Appium v2.x. Today I updated the mac to Sequoia15 version which updated the XCode to v16. Just after this update, I could not able to run the previously running automation script. The console message is "org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: Unable to launch WebDriverAgent. Original error: xcodebuild failed with code 70. This usually indicates an issue with the local Xcode setup or WebDriverAgent project configuration or the driver-to-platform version mismatch."
2
0
516
Sep ’24
XCTest to test EndpointSecurity error,ES_NEW_CLIENT_RESULT_ERR_NOT_PRIVILEGED
I tried to use XCTest to test my own project that uses EndpointSecurity, but when I created the esClient I got an error:ES_NEW_CLIENT_RESULT_ERR_NOT_PRIVILEGED, indicating that it was not root. This makes it impossible for me to do coverage tests for the ESClient application. Is there any way I can implement this ESClient test? If so, how should I use it? The project is a macOS program, if I use gcov, but I find I can't get coverage. Using __gcov_flush will indicate that there is no symbol #if !TARGET_IPHONE_SIMULATOR NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; setenv("GCOV_PREFIX", [documentsDirectory cStringUsingEncoding:NSUTF8StringEncoding], 1); setenv("GCOV_PREFIX_STRIP", "13", 1); #endif extern void __gcov_flush(void); __gcov_flush(); #endif
3
0
435
Sep ’24
[MT] DVTAssertions: ASSERTION FAILURE in IDEFrameworks/IDEFoundation/ProjectModel/ActionRecords/IDESchemeActionsInvocationRecord.m:458
I am creating a iOS library project using Xcode 15 in objective C lang which has dependency XCTest framework and Objective C run time and having UI test cases which can be use used in various projects. I am able to build and run unit test cases using Xcode fine but when try to run test using command line getting below issue Command env NSUnbufferedIO=YES xcodebuild clean test -workspace EnptyLibrary.xcworkspace -scheme EnptyLibrary -configuration Debug -destination 'platform=iOS Simulator,OS=latest,name=iPhone 15 Pro' -destination 'platform=iOS Simulator,OS=latest,name=iPad Pro (12.9-inch) (6th generation)' -testPlan EnptyLibrary -derivedDataPath build -disable-concurrent-destination-testing -retry-tests-on-failure=NO Error log ** TEST SUCCEEDED ** 2024-09-12 16:36:34.822 xcodebuild[8345:45388802] Writing error result bundle to /var/folders/12/rcxtcvjs08169cc_fzhyc8x40000gq/T/ResultBundle_2024-12-09_16-36-0034.xcresult 2024-09-12 16:36:34.832 xcodebuild[8345:45388802] [MT] DVTAssertions: ASSERTION FAILURE in IDEFrameworks/IDEFoundation/ProjectModel/ActionRecords/IDESchemeActionsInvocationRecord.m:458 Details: Assertion failed: !self.hasSaved Object: <IDESchemeActionsInvocationRecord: 0x112c21ce0> Method: -saveWithCompletionBlock: Thread: <_NSMainThread: 0x600000e441c0>{number = 1, name = main} Hints: Backtrace: 0 -[DVTAssertionHandler handleFailureInMethod:object:fileName:lineNumber:assertionSignature:messageFormat:arguments:] (in DVTFoundation) 1 _DVTAssertionHandler (in DVTFoundation) 2 _DVTAssertionFailureHandler (in DVTFoundation) 3 _DVTAssertionWarningHandler (in DVTFoundation) 4 -[IDESchemeActionsInvocationRecord saveWithCompletionBlock:] (in IDEFoundation) 5 -[IDESchemeActionsInvocationRecord saveSynchronouslyWithError:] (in IDEFoundation) 6 -[Xcode3CommandLineBuildTool saveResultBundleForError:triageWithSchemeTask:error:] (in Xcode3Core) 7 -[Xcode3CommandLineBuildTool _printError:schemeTask:andFailWithCode:] (in Xcode3Core) 8 -[Xcode3CommandLineBuildTool _printErrorWithSchemeTaskUserInfo:] (in Xcode3Core) 9 -[Xcode3CommandLineBuildTool _buildWithTimingSection:] (in Xcode3Core) 10 -[Xcode3CommandLineBuildTool run] (in Xcode3Core) 11 XcodeBuildMain (in libxcodebuildLoader.dylib) 12 -[XcodebuildPreIDEHandler loadXcode3ProjectSupportAndRunXcode3CommandLineBuildToolWithArguments:] (in xcodebuild) 13 -[XcodebuildPreIDEHandler runWithArguments:] (in xcodebuild) 14 main (in xcodebuild) 15 start (in dyld) zsh: abort env NSUnbufferedIO=YES xcodebuild clean test -workspace -scheme EnptyLibrary
0
0
340
Sep ’24
XCode 16 RC and Sequoia 15 RC - Running a XCTest UI test runs the test but does not open the simulator and initiating a record just hangs and never runs
When I run a XCTest test on an IOS Target device, the test runs but the simulator is not opened so I can follow the screens being displayed and the key strokes. And when I initiate a record for a test method, it just hangs and never runs or open a simulator. Is anyone else experiencing these same issues running XCTest? Is this legacy framework not working with XCode 16 by design?
3
1
484
Sep ’24
Unable to Launch Tests/UITests in Xcode 16 with iOS 18 Simulator
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
7
2
869
2w
WeScan.ImageScannerControllerError iPhone Simulator
Hi everyone, I've got an issue with the iPhone simulator version 15 iOS 17.0. Every time a test attempts to take a photo, the app directs to the camera software and then this error appears. For my colleagues instead, they've been directed to the gallery. The only difference is that my machine is M1 while theirs is with Intel chip. I'm using MacOS 13.6.3, the same as them. Does anyone have any idea why this could happen? Thank you in advance.
0
0
239
Aug ’24
XCTest stuck and has error when take snapshot element on screen has much elements
Dear Apple Developer [Background] We are developing a service running on test mode based on XCTest Framework to support streaming, remote and automation testing with iOS devices. After we upgrade macOS Sonama and Xcode 15 version for upgrade XCTest for support iOS 17 around Jan-2024, we saw We noticed that our running on test mode services stuck and hanging frequently after a period of time. We have investigate and tried debug code and we found that main thread stuck and hanging when it call requesting snapshot of accessibility hierarchy for app. At the same time, we noticed that the application we were testing stuck and hanging too. [Environment] Application testing: Tiktok MacOS: Sonoma 14.5 Xcode: Version 15.4 (15F31d) Device test: iPhone 12 (iOS 14.8.1) Log detail: t = 1524.15s Wait for com.ss.iphone.ugc.Ame to idle t = 1536.54s Find the Application 'com.ss.iphone.ugc.Ame' t = 1536.54s Requesting snapshot of accessibility hierarchy for app with pid 509 t = 1597.56s Find the Application 'com.ss.iphone.ugc.Ame' (retry 1) t = 1597.56s Requesting snapshot of accessibility hierarchy for app with pid 509 t = 1658.58s Find the Application 'com.ss.iphone.ugc.Ame' (retry 2) t = 1658.58s Requesting snapshot of accessibility hierarchy for app with pid 509 t = 1718.58s Collecting extra data to assist test failure triage t = 1718.58s Requesting snapshot of accessibility hierarchy for app with pid 509 t = 1778.59s Requesting snapshot of accessibility hierarchy for app with pid 509 2024-08-19 14:16:44.990260+0700 WebDriverAgentRunner-Runner[489:97809] Issue type: 0 2024-08-19 14:16:44.990428+0700 WebDriverAgentRunner-Runner[489:97809] Enqueue Failure: Failed to get matching snapshot: XCTPerformOnMainRunLoop work timed out after 60.0s ((null)) (null) 0 0 t = 1843.71s Find the Application 'com.ss.iphone.ugc.Ame' t = 1843.71s Requesting snapshot of accessibility hierarchy for app with pid 509 t = 1874.72s Find the Application 'com.ss.iphone.ugc.Ame' (retry 1) t = 1874.72s Requesting snapshot of accessibility hierarchy for app with pid 509 t = 1940.76s Find the Application 'com.ss.iphone.ugc.Ame' (retry 2) t = 1940.77s Requesting snapshot of accessibility hierarchy for app with pid 509 t = 2005.80s Collecting extra data to assist test failure triage t = 2005.80s Requesting snapshot of accessibility hierarchy for app with pid 509 t = 2066.58s Requesting snapshot of accessibility hierarchy for app with pid 509 2024-08-19 14:21:33.019582+0700 WebDriverAgentRunner-Runner[489:97809] Issue type: 0 2024-08-19 14:21:33.019687+0700 WebDriverAgentRunner-Runner[489:97809] Enqueue Failure: Failed to get matching snapshot: Unable to perform work on main run loop, process main thread busy for 30.0s ((null)) (null) 0 0 2024-08-19 14:21:33.020647+0700 WebDriverAgentRunner-Runner[489:97809] Issue type: 0 2024-08-19 14:21:33.020722+0700 WebDriverAgentRunner-Runner[489:97809] Enqueue Failure: No element snapshot found for Application 'com.ss.iphone.ugc.Ame'[0.00, 0.00] -> (200.0, 259.0) ((null)) (null) 0 0 2024-08-19 14:21:33.020801+0700 WebDriverAgentRunner-Runner[489:97809] *** Assertion failure in -[XCPointerEventPath initForTouchAtPoint:offset:], XCSynthesizedEventRecord.m:263 t = 2291.08s Find the Application 'com.ss.iphone.ugc.Ame' t = 2291.08s Requesting snapshot of accessibility hierarchy for app with pid 509 t = 2352.10s Find the Application 'com.ss.iphone.ugc.Ame' (retry 1) t = 2352.10s Requesting snapshot of accessibility hierarchy for app with pid 509 t = 2413.11s Find the Application 'com.ss.iphone.ugc.Ame' (retry 2) t = 2413.11s Requesting snapshot of accessibility hierarchy for app with pid 509 t = 2473.12s Collecting extra data to assist test failure triage t = 2473.12s Requesting snapshot of accessibility hierarchy for app with pid 509 t = 2533.13s Requesting snapshot of accessibility hierarchy for app with pid 509 2024-08-19 14:29:19.552744+0700 WebDriverAgentRunner-Runner[489:97809] Issue type: 0 2024-08-19 14:29:19.553054+0700 WebDriverAgentRunner-Runner[489:97809] Enqueue Failure: Failed to get matching snapshot: XCTPerformOnMainRunLoop work timed out after 60.0s ((null)) (null) 0 0 t = 2598.27s Find the Application 'com.ss.iphone.ugc.Ame' t = 2598.28s Requesting snapshot of accessibility hierarchy for app with pid 509 t = 2659.29s Find the Application 'com.ss.iphone.ugc.Ame' (retry 1) t = 2659.29s Requesting snapshot of accessibility hierarchy for app with pid 509 t = 2720.31s Find the Application 'com.ss.iphone.ugc.Ame' (retry 2) t = 2720.32s Requesting snapshot of accessibility hierarchy for app with pid 509 t = 2780.33s Collecting extra data to assist test failure triage t = 2780.33s Requesting snapshot of accessibility hierarchy for app with pid 509 t = 2840.34s Requesting snapshot of accessibility hierarchy for app with pid 509 2024-08-19 14:34:26.806686+0700 WebDriverAgentRunner-Runner[489:97809] Issue type: 0 2024-08-19 14:34:26.806828+0700 WebDriverAgentRunner-Runner[489:97809] Enqueue Failure: Failed to get matching snapshot: XCTPerformOnMainRunLoop work timed out after 60.0s ((null)) (null) 0 0 2024-08-19 14:34:26.808114+0700 WebDriverAgentRunner-Runner[489:97809] Issue type: 0 2024-08-19 14:34:26.808205+0700 WebDriverAgentRunner-Runner[489:97809] Enqueue Failure: No element snapshot found for Application 'com.ss.iphone.ugc.Ame'[0.00, 0.00] -> (200.0, 259.0) ((null)) (null) 0 0 2024-08-19 14:34:26.809241+0700 WebDriverAgentRunner-Runner[489:97809] *** Assertion failure in -[XCPointerEventPath initForTouchAtPoint:offset:], XCSynthesizedEventRecord.m:263
1
0
408
Aug ’24
Deadlock in UIKit while injecting test bundle
Platform and Version iOS Development environment: Xcode 16.0 beta 5 (16A5221g), macOS 14.6.1 (23G93) Run-time configuration: iOS 18.0 beta 5 (22A5326g) Description of Problem Starting with iOS 18 SDK, test bundles containing a +load method that accesses UIScreen.mainScreen result in deadlock during test bundle injection. Also filed as FB14703057 I'm looking for clarity on whether this behavior is considered a bug in iOS or whether we will need to change the implementation of our app. Steps to Reproduce Create a new iOS app project using Objective-C and including unit tests Add the following code snippet to any .m file in the test target: @interface Foo: NSObject @end @implementation Foo + (void)load { UIScreen * const mainScreen = UIScreen.mainScreen; NSLog(@"%@", mainScreen); } @end Run the tests Expected Behavior As with iOS 17 & Xcode 15, the tests run to completion. Actual Behavior With iOS 18 & Xcode 16, deadlock during test bundle injection. stack_trace.txt
2
0
481
Sep ’24