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

Posts under XCTest tag

160 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Documents are locked when opened under XC UI Testing
Got an issue with XC UI Testing where I can't open documents without them being marked as locked (the Locked label is shown in the titlebar). The document in question is a testing asset and copied into the testing bundle for easy access. I've checked the file in bundle in Finder and the document is not marked as locked. I've also tried copying the document to a temp directory before opening it and it's still locked?! What's the trick for getting it to open without being locked?
1
0
343
May ’24
xcbuild didn't run tests even though it can be run from XCode
I am trying to do the tests form the terminal and xcpretty the output. Here is the command: xcodebuild -workspace bimb-authenticate-ios.xcworkspace -scheme bimb-authenticate-ios-afx -configuration Debug -destination 'platform=iOS Simulator,name=iPhone 14 Pro,OS=16.4' -enableCodeCoverage YES -derivedDataPath Build/ clean build test | xcpretty -c "--report" "html" "--output" "../Project_report.html" However, the tests are never run. The simulator is not even opened. Here's the last items of the xcbuild logs: ... *compiling, linting and linking logs* 2024-03-27 21:42:37.151 xcodebuild[84540:2237180] [MT] IDETestOperationsObserverDebug: 264.553 elapsed -- Testing started completed. 2024-03-27 21:42:37.152 xcodebuild[84540:2237180] [MT] IDETestOperationsObserverDebug: 0.001 sec, +0.001 sec -- start 2024-03-27 21:42:37.152 xcodebuild[84540:2237180] [MT] IDETestOperationsObserverDebug: 264.554 sec, +264.553 sec -- end ▸ Test Succeeded Can anybody help me? Thanks.
0
0
395
Mar ’24
Test plans being deleted and replaced by old test schemes
I am currently using Xcode 15.2, but I am sure this issue exists on other versions too. If you have any packages made pre Xcode 14.3, i.e. ones without an automatically made test plan, then the following issue happens: Let's call the package in this example PackageX, and you have with this a corresponding test scheme, called PackageXTests. PackageXTests is a test scheme saved on disk, that is on the test scheme of PackageX, meaning that when you test the package directly, it will run the test scheme. Now, with test plans becoming the norm, we want to move away from having these test schemes on disk and instead align old packages with new and have each package's tests dictated by its own corresponding test plan, the same way that any newly made package would work. So we click 'convert to test plan', success we have a test plan, we delete the test scheme from the disk. All appears to be working fine. However, if you now swap branch and come back, the test plan will no longer be connected to that package. It will have reverted back to a test scheme. Which in git shows as a test scheme which it has added (i.e. the git diff has an uncommitted test scheme it has made). This is not a derived data issue, as I have deleted my derived data and it still occurs. Similarly with cleaning and building.
0
0
493
Mar ’24
Xcode Loading Test... Stuck
Since couple of weeks ago (probably after I've updated my macbook to Sonoma 14.3.1) my Xcode cannot load unit test. When opening Test Navigator all I see is: Loading Tests... and it stays forever in that state. This is completely new project and this is crazy. Only way I can start testing is if I use CMD+U to run all the tests which is my company's project take a lot of time. Also there's no option to click on test-diamond-shaped button to run individual tests. Also tried checking "Test Plans" but I have infinite progress views: Anyone has any idea how to fix this? I tried to remove Derived Data, to reinstall Xcode (and different versions), did "git clean -fxd" nothing helped. Also some function like: "Rename", "Edit all in scope" stopped working as well.
0
0
391
Mar ’24
UI tests on Xcode Cloud became unstable when switched environment to Sonoma
My project has UI tests with total length of ~50 minutes. I'm using Xcode Cloud for builds delivery, UI tests execution is the part of the workflow. When I was using Monterey as tests environment everything was fine, but now it's no longer available so i had to switch to Sonoma. Since this i wasn't able to run anything but a couple of separate UI tests, when I run all of them I'm having 2 major issues. Locally on my machine I have the same Xcode/MacOS/simulator versions and everything works perfectly, issues only appear on Xcode Cloud. Here are they: There is a huge time gap between build-for-testing is finished and test-without-building is started. The gap is more than 1 hour so the sum of build time, ui tests time and the gap results in more than 2 hours and tests execution fails with the timeout. Funny is when I try to run the a single UI test or just run unit tests this gap only lasts for like 2-6 minutes, but when I add more tests the gap goes huge and fails everything. Also I guess my company is paying for those gaps and runs of tests when they timeout because of it even tho it's not our fault. Second issue is that some UI tests just freeze in the meddle of execution. This happens when UI tests is trying to interact with text fields on modal view controllers, sometimes it happens during the text field lookup, sometimes - after it takes focus and test is trying to type things into it. This is cannot be dodged anyhow and it is not related to some specific code - I've intentionaly rewritten the whole view controller from UIKit to SwiftUI , changed the way I present it and the location of presentation. Looks like just having a text field on a modal view is enough for test to freeze. Have anyone experienced something like this? Found any solutions?
3
3
791
May ’24
XCUITests running incredibly slow with Xcode 15.3
Sometime recently our XCUITests started to hang after awhile and so I had filed this Feedback ticket. With the release of Xcode 15.3 I re-ran the test in the project I had attached to that Feedback ticket (which taps a "Go!" button which pushes a new view controller and then verifies the value of a UILabel) and the tests are running crazy slow on a device now running iOS 17.4. It has been half an hour and only 14 of 100 iterations have been run. Anyone else experience severe performance degradation in their XCUITests with Xcode 15.3?
2
0
671
May ’24
Unit testing [XCTest]
Hello world, I'm doing unit testing with Swift. I need to create a test for the registration process of an application. When I register, a confirmation link is sent to the specified email. How can I create a test that allows me to access the email and click on the link to confirm the registration?
0
0
333
Mar ’24
Is there anyone who knows the secrets of RuntimeMap.plist?
Hi, I'm in the team maintaining company-wise CI for iOS build and test, which runs over 100 macs on the system with every stable versions of Xcode/simulators and the latest beta/rc. I've been terribly suffered from xcodebuild test failure with simulator destination on Xcode beta series since Xcode 14.x has changed its CoreSimulator behavior from static simruntime into simdisk-based dynamic runtime. (If you search for xcrun simctl runtime match set 'watchos9.1' 20S75 you can check what I have been fighting for.) At the end of numerous nightly overtimes I finally found out that ~/Library/Developer/CoreSimulator/RuntimeMap.plist is closely related to xcrun simctl runtime match command. If CoreSimulatorService relaunches when RuntimeMap.plist is corrupted (or missing), Chosen Runtime will be set as default SDK (pretty sure it is SDK version of iphoneos, not iphonesimulator) ex) $ sudo xcode-select -s /Applications/Xcode_15.2.app $ sed -i '' -e 's|21C62|21Cblabla|' ~/Library/Developer/CoreSimulator/RuntimeMap.plist $ sudo pkill -9 com.apple.CoreSimulator.CoreSimulatorService $ xcrun simctl runtime match list == Evaluation Results == appletvos17.2: SDK Version: 17.2 SDK Build: 21K354 Platform: com.apple.platform.appletvos Chosen Runtime: tvOS 17.2 (17.2 - 21K364) - com.apple.CoreSimulator.SimRuntime.tvOS-17-2 User Override: (null) Preferred: tvOS 17.2 (17.2 - 21K364) - com.apple.CoreSimulator.SimRuntime.tvOS-17-2 Default: 21K354 iphoneos17.2: SDK Version: 17.2 SDK Build: 21C52 Platform: com.apple.platform.iphoneos Chosen Runtime: 21C52 User Override: (null) Preferred: 21Cblabla Default: 21C52 watchos10.2: SDK Version: 10.2 SDK Build: 21S355 Platform: com.apple.platform.watchos Chosen Runtime: watchOS 10.2 (10.2 - 21S364) - com.apple.CoreSimulator.SimRuntime.watchOS-10-2 User Override: (null) Preferred: watchOS 10.2 (10.2 - 21S364) - com.apple.CoreSimulator.SimRuntime.watchOS-10-2 Default: 21S355 xros1.0: SDK Version: 1.0 SDK Build: 21N301 Platform: com.apple.platform.xros Chosen Runtime: visionOS 1.0 (1.0 - 21N305) - com.apple.CoreSimulator.SimRuntime.xrOS-1-0 User Override: (null) Preferred: visionOS 1.0 (1.0 - 21N305) - com.apple.CoreSimulator.SimRuntime.xrOS-1-0 Default: 21N301 The question is: Where exactly is the path or file that reflects this change? What file is Chosen Runtime of runtime match list tracking? When is the time to re-download and fix if it is corroded or not found? P.S. Thanks valexeev4 for letting me know where RuntimeMap plist is. https://developer.apple.com/forums/thread/738077?answerId=765617022#765617022
0
0
442
Mar ’24
Xcode 15 + UI tests: text field timeout
Hello! Since Xcode 15 came out, I've been having this issue with UI tests where the test runner hangs for 60s when the keyboard is presented. In the test logs I get this kind of messages: 00:07.588 Wait for com.example.app to idle 01:07.642 App event loop idle notification not received, will attempt to continue. Interestingly, this only appears to be happening in CI environments (I've tried Xcode cloud and Circle CI). It works fine on my local machine. Everything is fine with Xcode 14, but I can't keep my CI environment stuck on Xcode 14 forever. I've tried disabling animations using UIView.setAnimationsEnabled(false), but it did not fix the problem. Here are the full logs of what it takes to fill out a text field: logs.txt
2
1
784
May ’24
Unit test SwiftData migrations
I'm trying to write a unit test for a SwiftData migration. In the teardown function I delete the SQLite container files, but then the underlying sqlite library complains. There must be a way to gracefully terminate the SwiftData container before I delete the files, but I don't see how. Simplying nil-ifying the references doesn't work. I don't see any obvious close functions, so I hope someone knows a non-obvious function. override func tearDownWithError() throws { // Cleanup resources // -- DOES NOT CLOSE UNDERLYING SQLITE ACCESS -- self.container = nil self.context = nil // Delete database do { try FileManager.default.removeItem(at: self.url) } catch { // Ignore file not found, report everything else. let nserror = error as NSError if nserror.domain != "NSCocoaErrorDomain" && nserror.code == 4 { throw error } } try? FileManager.default.removeItem(at: self.url.deletingPathExtension().appendingPathExtension("store-shm")) try? FileManager.default.removeItem(at: self.url.deletingPathExtension().appendingPathExtension("store-wal")) } I get these errors for .store, store-shm, and .store-wal: BUG IN CLIENT OF libsqlite3.dylib: database integrity compromised by API violation: vnode unlinked while in use: /Users/(ME)/Library/Developer/XCTestDevices/C52F4E12-EB4F-4639-9866-C3A7126155FA/data/Containers/Data/Application/B0EE90C6-B95D-4185-890D-6F20766B9B3B/tmp/test1.store invalidated open fd: 11 (0x11) If the worst comes to the worst, I'll work around it by using a differently-named container for each test, but as they're in tmp they'll get cleaned up for me eventually.
1
0
537
Feb ’24
XCTest '-enablePerformanceTestsDiagnostics' not generating memgraph.
I am running xctests from command line on XCode 15.2 on iOS 17.2 simulators. As per WWDC2021 video on Memory issues, I am passing `-enablePerformanceTestsDiagnostics Yes' in following xcodebuild command. xcodebuild test -project project_name.xcodeproj -scheme test-scheme -destination 'platform=iOS Simulator,name=iPhone 15 Pro' -enablePerformanceTestsDiagnostics YES Final logs before test results: Tests-Runner(16873) MallocStackLogging: stack logs deleted from /private/tmp/stack-logs.16873.10148c000.Tests-Runner.M6gFw .xcresults is generated but no memgraph file is attached along with it.
0
0
507
Feb ’24
Crash reports not attached to xcresult when running with xcodebuild
Hi there, I'm trying to figure out an issue I'm seeing where the xcresult bundle isn't including the crash report after building and running with xcodebuild. I have a simple test app that has a single button that intentionally crashes and an XCUI test to run it. The UI Test also passes which can probably be explained by the lack of any asserts after clicking the button, but I assumed the app crashing would fail the test. The app itself is a Mac OS app with a single button called "Crash" that links to a method: - (IBAction)crash:(id)sender { @throw NSInternalInconsistencyException; } and a test method: XCUIApplication *app = [[XCUIApplication alloc] init]; [app launch]; XCUIElement *crashButton = [[XCUIApplication alloc] init].windows[@"Window"].buttons[@"Crash"]; XCTAssert([crashButton exists]); [crashButton click]; There is an ips file corresponding to the crash in ~/Library/Logs/DiagnosticReports so the crash gets written, but the test passes. After using xcresulttool to dump the Diagnostics folder from the xcresult bundle, I see these lines in the session log: 10:59:20.790 xcodebuild[23184:6634391] Handling Crash: MacAppTest (23189) main. libsystem_c.dylib: abort() called 10:59:20.792 MacAppTestUITests-Runner[23188:6635181] Process crashed with pid:23189 path:/Users/USER/Library/Developer/Xcode/DerivedData/MacAppTest-dxrjhasbuvyffhenipmdemzdpdht/Build/Products/Debug/MacAppTest.app/Contents/MacOS/MacAppTest bundleID:com.company.MacAppTest summary:main 10:59:20.792 MacAppTestUITests-Runner[23188:6635181] Ignoring crash for com.company.MacAppTest:23189 because we are not currently tracking it 10:59:21.371 MacAppTestUITests-Runner[23188:6634605] Returning result XCTWaiterResultCompleted for waiter <XCTWaiter: 0x6000025fd4d0> 10:59:21.371 MacAppTestUITests-Runner[23188:6634605] Wait <XCTWaiterWait: 0x600003e1b540> completed after 1.003s 10:59:21.371 MacAppTestUITests-Runner[23188:6634605] cleaning up delay The Ignoring crash for com.company.MacAppTest:23189 because we are not currently tracking it is what I suspect is the issue. How can I get the UITest to track the app so that when it crashes, the test fails? Some other lines from the logarchive file that may be helpful: 2024-02-14 10:59:20.612346 -0800 osanalyticshelper xpc log creation type 309 result success: /Users/<REDACTED>/Library/Logs/DiagnosticReports/MacAppTest-2024-02-14-105920.ips 2024-02-14 10:59:20.613030 -0800 testmanagerd Calling new file handler <__NSMallocBlock__: 0x6000031761f0> for MacAppTest-2024-02-14-105920.ips 2024-02-14 10:59:20.614240 -0800 ReportCrash client log create type 309 result success: /Users/<REDACTED>/Library/Logs/DiagnosticReports/MacAppTest-2024-02-14-105920.ips 2024-02-14 10:59:20.615417 -0800 testmanagerd Read crash report from /Users/<REDACTED>/Library/Logs/DiagnosticReports/MacAppTest-2024-02-14-105920.ips, got 17327 bytes of data Thanks!
0
0
550
Feb ’24
Xc15.3B3 Fails init on iPhone 14(+pro/promax/plus) and iPad 10th gen sims
I'm trying some sample with xcodebuild test command for i(Pad)OS simulators, figuring out some strange behavior on simulator initiation. 00:00:38 -------------------------- 00:00:38 --- Step: xcode_select --- 00:00:38 -------------------------- 00:00:38 Setting Xcode version to /Applications/Xcode/Xcode_15.3_beta_3.app for all build steps 00:00:38 Init simulators ... 00:00:39 $DEVELOPER_DIR 00:00:39 /Applications/Xcode/Xcode_15.3_beta_3.app/Contents/Developer ... 00:05:26 ▸ 2024-02-14 15:13:41.319 xcodebuild[12903:1082819] [MT] IDELaunchReport: 4a4f919bfba30580:4a4f919bfba30580: Finished with error: Simulator device failed to install the application. 00:05:26 ▸ Domain: IXErrorDomain 00:05:26 ▸ Code: 2 00:05:26 ▸ Failure Reason: Failed to locate promise. 00:05:26 ▸ User Info: { 00:05:26 ▸ FunctionName = "+[IXPlaceholder _placeholderForBundle:client:withParent:installType:metadata:placeholderType:mayBeDeltaPackage:error:]"; 00:05:26 ▸ IDERunOperationFailingWorker = IDELaunchiPhoneSimulatorLauncher; 00:05:26 ▸ SimCallingSelector = "installApplication:withOptions:error:"; 00:05:26 ▸ SourceFileLine = 803; 00:05:26 ▸ } 00:05:26 ▸ -- 00:05:26 ▸ Failed to set icon promise for com.example.myapp 00:05:26 ▸ Domain: IXErrorDomain 00:05:26 ▸ Code: 2 00:05:26 ▸ Failure Reason: Failed to create promise. 00:05:26 ▸ User Info: { 00:05:26 ▸ FunctionName = "+[IXPlaceholder _placeholderForBundle:client:withParent:installType:metadata:placeholderType:mayBeDeltaPackage:error:]"; 00:05:26 ▸ SourceFileLine = 803; 00:05:26 ▸ } 00:05:26 ▸ -- 00:05:26 ▸ Placeholder did not exist for UUID 2810E06A-4565-4966-BE98-AE4A6A96D916 when called for -[IXSClientConnection _remote_IXSPlaceholder:setIconPromiseUUID:completion:] by client CoreSimulatorBridge (pid 13037) 00:05:26 ▸ Domain: IXErrorDomain 00:05:26 ▸ Code: 3 00:05:26 ▸ Failure Reason: Failed to locate promise. 00:05:26 ▸ User Info: { 00:05:26 ▸ FunctionName = "-[IXSClientConnection _fetchPlaceholderForUUID:method:andRunWithPromise:error:]"; 00:05:26 ▸ SourceFileLine = 1945; 00:05:26 ▸ } 00:05:26 ▸ -- 00:05:26 ▸ 2024-02-14 15:13:41.323 xcodebuild[12903:1082819] [MT] IDELaunchReport: 4a4f919bfba30580:4a4f919bfba30580: com.apple.dt.IDERunOperationWorkerFinished { 00:05:26 ▸ "device_model" = "iPhone14,7"; 00:05:26 ▸ "device_osBuild" = "16.4 (20E247)"; 00:05:26 ▸ "device_platform" = "com.apple.platform.iphonesimulator"; 00:05:26 ▸ "dvt_coredevice_version" = "355.23"; 00:05:26 ▸ "dvt_mobiledevice_version" = "1643.100.52"; 00:05:26 ▸ "launchSession_schemeCommand" = Test; 00:05:26 ▸ "launchSession_state" = 1; 00:05:26 ▸ "launchSession_targetArch" = arm64; 00:05:26 ▸ "operation_duration_ms" = 108400; 00:05:26 ▸ "operation_errorCode" = 2; 00:05:26 ▸ "operation_errorDomain" = IXErrorDomain; 00:05:26 ▸ "operation_errorWorker" = IDELaunchiPhoneSimulatorLauncher; 00:05:26 ▸ "operation_name" = IDERunOperationWorkerGroup; 00:05:26 ▸ "param_debugger_attachToExtensions" = 0; 00:05:26 ▸ "param_debugger_attachToXPC" = 0; 00:05:26 ▸ "param_debugger_type" = 1; 00:05:26 ▸ "param_destination_isProxy" = 0; 00:05:26 ▸ "param_destination_platform" = "com.apple.platform.iphonesimulator"; 00:05:26 ▸ "param_diag_MainThreadChecker_stopOnIssue" = 0; 00:05:26 ▸ "param_diag_MallocStackLogging_enableDuringAttach" = 0; 00:05:26 ▸ "param_diag_MallocStackLogging_enableForXPC" = 0; 00:05:26 ▸ "param_diag_allowLocationSimulation" = 1; 00:05:26 ▸ "param_diag_checker_tpc_enable" = 0; 00:05:26 ▸ "param_diag_gpu_frameCapture_enable" = 3; 00:05:26 ▸ "param_diag_gpu_shaderValidation_enable" = 0; 00:05:26 ▸ "param_diag_gpu_validation_enable" = 1; 00:05:26 ▸ "param_diag_memoryGraphOnResourceException" = 0; 00:05:26 ▸ "param_diag_queueDebugging_enable" = 1; 00:05:26 ▸ "param_diag_runtimeProfile_generate" = 1; 00:05:26 ▸ "param_diag_sanitizer_asan_enable" = 0; 00:05:26 ▸ "param_diag_sanitizer_tsan_enable" = 0; 00:05:26 ▸ "param_diag_sanitizer_tsan_stopOnIssue" = 0; 00:05:26 ▸ "param_diag_sanitizer_ubsan_stopOnIssue" = 0; 00:05:26 ▸ "param_diag_showNonLocalizedStrings" = 0; 00:05:26 ▸ "param_diag_viewDebugging_enabled" = 0; 00:05:26 ▸ "param_diag_viewDebugging_insertDylibOnLaunch" = 0; 00:05:26 ▸ "param_install_style" = 2; 00:05:26 ▸ "param_launcher_UID" = 2; 00:05:26 ▸ "param_launcher_allowDeviceSensorReplayData" = 0; 00:05:26 ▸ "param_launcher_kind" = 0; 00:05:26 ▸ "param_launcher_style" = 0; 00:05:26 ▸ "param_launcher_substyle" = 0; 00:05:26 ▸ "param_runnable_appExtensionHostRunMode" = 0; 00:05:26 ▸ "param_runnable_productType" = "com.apple.product-type.application"; 00:05:26 ▸ "param_structuredConsoleMode" = 0; 00:05:26 ▸ "param_testing_launchedForTesting" = 1; 00:05:26 ▸ "param_testing_suppressSimulatorApp" = 1; 00:05:26 ▸ "param_testing_usingCLI" = 0; 00:05:26 ▸ "sdk_canonicalName" = "iphonesimulator17.4"; 00:05:26 ▸ "sdk_osVersion" = "17.4"; 00:05:26 ▸ "sdk_variant" = iphonesimulator; 00:05:26 ▸ } When I choose iPad 10th Generation, iPhone 14, 14 plus, 14 pro or 14 pro max devices listed on xcrun simctl list it fails with the log above. (doesn't matter what OS version is selected) Other than those sims it works (I checked it on iPhone SE 3rd gen, ipad mini 6g) Are those devices excluded from Xcode 15.3 Beta 3? Then why are those on the xcrun simctl list still? FYI: myapp took -Wl and -ld_classic for OTHER_LDFLAGS option in xcconfig after first app installation crash, still didn't make any changes.
0
0
449
Feb ’24
Unit Testing Hangs on xCode 15
Hello, I'm having an issue with Unit testing on xCode 15.2 and macOS Sonoma. I'm trying to run unit testing and it hangs for a long time and then fails, previously I was able to run my unit testing on simulator with iOS 14, however after upgrading the xCode and the macOS I'm unable to use simulators with iOS 14 and my unit testing keeps failing. I have another device which is running macOS Ventura and I can run my unit testing on it without any problems using simulators with iOS 14 on xCode 15.0. Please note the issue is not with the xCode version because I tried downgrading and still have the same issue. I tried every solution i can find on this forum and others, I couldn't find anything that would help. I can't attach the dump log file directly since it's big so please use the link below https://drive.google.com/file/d/1v_gpCLhEuUdqFF6aCfrGislYWV8ZE8Qm/view?usp=share_link
1
0
852
Feb ’24