when I download the sample backyard app from wwdc 23. The files for the Unit and Ui test are missing. Where do I find the? since I would like to see how they Apple implemented unit tests with SwiftData
XCTest
RSS for tagCreate 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
Not able to capture individual elements on the home screen of iOS17 device with xCode 15 and appium2
Not able to capture the individual elements on the iOS 17 device (using iPhone 14) using Appium inspector.
It always capture/ highlight the entire home screen as one element.
As per the Appium support team, this is an issue with XCTest framework.
The getPageSource() method is loading indefinitely.
Please refer below links-
https://github.com/appium/appium-inspector/issues/1225
https://github.com/appium/appium/issues/19429
I am using below configurations-
MacBook AIR (Apple M2 2022) - Sonoma 14.1.2
Appium Version - 2.0.1
Appium Inspector - 2023.11.1
Available drivers:
xcuitest@5.11.8 (automationName 'XCUITest')
uiautomator2@2.34.2 (automationName 'UiAutomator2')
Node - v21.3.0
npm - 10.2.4
Xcode - Version 15.0.1 (15A507)
Could you please clarify if this is an existing/known issue or am I missing something?
Note - Let me know if any other information needed from my end for better clarity.
I will appreciate your inputs on this.
Thanks in advance!
Hi, I'm new here, and I'm need to Developer Disk Image to Test my app, how can I get it?
I have a swift package with a function that formats a HKQuantity using the current locale. I want to write a unit test with all locales the package is localized for. I do not want to insert a separate locale parameter, I want to test the function with the current locale as I use the function only with the current locale.
Can I set the current locale for this use case in the code somehow?
Example:
do {
let quantity = HKQuantity(unit: unit, doubleValue: 0.955)
let result = quantity.formattedAsOxygenSaturation(precision: .better)
let expectedResult = "95.5 %"
XCTAssertEqual(result, expectedResult)
}
Thanks!
I facing the similar issue where Appium inspector is very slow to load my device, which makes me unable to locate the element.
MacBook Pro (Apple M1 Prod) - Ventura 13.6
Appium Version - 2.2.1
Appium Inspector - 2023.11.1
appium driver list
✔ Listing available drivers
uiautomator2@2.34.0 [installed (npm)]
Node - v21.1.0
npm - 10.2.0
Xcode - Version 15.0.1 (15A507)
Simulator - iPhone 15 (17.0)
{ "appium:deviceName": "iPhone 15", "appium:app": "sim.app PATH", "appium:automationName": "XCUITest", "appium:platformName": "iOS", "appium:platformVersion": "17.0", "appium:bundleId": "com.xxxxxxx", "appium:usePrebuiltWDA": false }
https://github.com/appium/appium/issues/19382
In the following code, test 1 (test_postNotification) fails while test 2 (test_notificationsArePostedOnTheMainQueue) passes.
What concerns me, though, is that if I substitute the lines "let result = XCTWaiter.wait(for: [expectation], timeout: 0); XCTAssertEqual(result, .timedOut)" of test 2 with "wait(for: [expectation], timeout: 0.1)", then test number 1 passes.
I have cleaned the build folder and restarted Xcode and my computer, but the issue persists.
This concerns me because I would have said that the tests of the NotificationPosterTests class were isolated, but apparently they are not, since changing test 2 makes test 1 go from failing to passing.
Is this expected behavior?
import Foundation
import XCTest
extension Notification.Name {
static let menuPostRequest = Notification.Name("menuPostRequest")
static let editingOrderError = Notification.Name("editingOrderError")
}
class NotificationPoster {
let notificationCenter: NotificationCenter
init(notificationCenter: NotificationCenter = .default) {
self.notificationCenter = notificationCenter
}
func postNotification(_ notification: Notification) {
let _notificationCenter = notificationCenter // you can't use optional chaining nor conditional unwrapping on self to reference self.notificationCenter in the dispatch block because self is nil when self.postNotification(_:) is called
DispatchQueue.main.async {
_notificationCenter.post(notification)
}
}
}
final class NotificationPosterTests: XCTestCase {
private var sut: NotificationPoster!
private var notificationCenter: NotificationCenter!
override func setUp() {
super.setUp()
notificationCenter = NotificationCenter()
sut = NotificationPoster(notificationCenter: notificationCenter)
}
override func tearDown() {
notificationCenter = nil
sut = nil
super.tearDown()
}
func test_postNotification() {
let notification = Notification(name: .menuPostRequest)
let expectation = XCTNSNotificationExpectation(
name: notification.name,
object: notification.object,
notificationCenter: notificationCenter
)
sut.postNotification(notification)
wait(for: [expectation], timeout: 0.1) // don't make it 0.01
}
func test_notificationsArePostedOnTheMainQueue() {
let notification = Notification(name: .editingOrderError)
let expectation = XCTNSNotificationExpectation(
name: notification.name,
object: notification.object,
notificationCenter: notificationCenter
)
sut.postNotification(notification)
let result = XCTWaiter.wait(for: [expectation], timeout: 0)
XCTAssertEqual(result, .timedOut)
}
}
webdriver: Request failed with status 500 due to An unknown server-side error occurred while processing the command. Original error: Unable to launch WebDriverAgent because of xcodebuild failure: xcodebuild failed with code 70
[0-0] xcodebuild error message:
[0-0] . Make sure you follow the tutorial at https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md. Try to remove the WebDriverAgentRunner application from the device if it is installed and reboot the device.
I'm using macOs 13.6
xcode 14.3
Iphone Os 16.7.2
running with webdriverIO
still getting this error can anyone help me in this please.
Hi community:
I found that after Xcode update from 14.3.1 to 15.0.1, my UITests fail only on the CI (Apple Xcode Cloud) because the use of boundElementsByIndex.
Seems that the use of this property stale the main thread:
Failed to resolve query: Unable to perform work on main run loop, process main thread busy for 30.0s
Is it a known issue?
Thanks
I'm trying to write performance tests with Xcode 15, but it's not working: even though setting a baseline seems to work (baseline data files are created), Xcode seems to ignore that baseline altogether whenever the test is run. As a result, performance tests never fail, no matter how bad performance gets.
The source editor persistently displays a “No baseline average for Time” message.
Has anyone else encountered this? Figured out how to sidestep the issue?
Of note, the issue is easily reproduced: create a new (macOS in my case) app project with tests, add a dummy performance test; run the test once and save its baseline, and despite this subsequent tests will always succeed, even if you significantly slow the dummy test down.
(I've filed this as FB13330139)
For my test automation project I use addUIInterruptionMonitor to keep the tests running smoothly. On iOS 17 this function seems to never get triggered. This code snippet contains a test that passes on iOS 15 and 16, but not on iOS 17 (tested on iPhone 12, iOS 15.5, iPhone 13 Mini, iOS 16.4.1 and iPhone 14 Pro, iOS 17.0).
To run the test, disable wifi and cell data on the test device first.
import XCTest
class Interruptions: XCTestCase {
func testCatchInterruption() {
// Run test on device with wifi and cell data disabled
var caughtInterruption = false
addUIInterruptionMonitor(withDescription: "Generic Alert Handler") { element -> Bool in
element.buttons["OK"].tap()
caughtInterruption = true
return true
}
let safariApp = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
safariApp.launch()
// Expect to see pop-up saying "Cellular Data is turned off"
safariApp.tap()
sleep(5)
// Pop-up should be gone
XCTAssert(caughtInterruption)
}
}
When using Xcode 15 beta 8 / iOS 17 beta 8 simulator runtime, we can see in Activity Monitor that memory used by "SimRenderServer" proccess grows significantly with each UI test run.
It reproduces even on an empty test, that just wait for a second without launching the application.
Memory usage doesn't go down when test run finishes, so each consecutive run adds more to it.
For example, create an new project with a UI test
// The contents of the test don't actually matter
func testExample() async throws {
try await Task.sleep(for: .seconds(1))
}
Run this test repeatedly 100+ times and observe the "SimRenderServer" process in the Activity Monitor.
From what we observed it only reproduces when "Preferred Capture Format" in the test plan configuration is set to "Video". Setting it back to "Screenshot" does no result in growing memory usage.
This was reproducible on macOS Sonoma beta / macOS Ventura 13.5.1.
Feedback was submitted FB13098749.
Xcode is throwing an error when attempting to report test coverage after running unit tests.
Showing All Messages
Failed to merge raw profiles in directory /{my project dir}/DerivedData/{my project name}/Build/ProfileData/A98EC493-3AB4-4B1C-B7FC-BC5D77B23EE3 to destination /{my project dir}/DerivedData/{my project name}/Build/ProfileData/A98EC493-3AB4-4B1C-B7FC-BC5D77B23EE3/Coverage.profdata: Aggregation tool '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/llvm-profdata' failed with exit code 1: warning: /{my project dir}/DerivedData/{my project name}/Build/ProfileData/A98EC493-3AB4-4B1C-B7FC-BC5D77B23EE3/997F01E3-3735-4897-AE00-31EBB0A9E8D3-57885.profraw: invalid instrumentation profile data (file header is corrupt)
error: no profile can be merged
Anyone else seeing this issue?
The new test report, with the automatic video recording and scrubber, is great. I'm setting up different configurations for different languages to improve localization testing, but I was wondering if it was possible to make the simulator device type part of the configuration.
For example, I'd like to have a single test plan with an "iPhone 14" test plan, an "iPad Air" test plan, etc. Then I would just press Cmd-U, and Xcode would run through each device in sequence, leaving me with videos of each test run that I could review in the test report.
Is that possible?
I've written a Swift package plugin to add the colours provided in the asset bundles in an extension of the SwiftUI Color type but I'm having difficulties testing this since the bundle and/or colour that is in the asset catalogs are not yet loaded when XCTest goes to evaluate the test conditions. Here is my test code: (colours are just random colours, some derive from macOS colour picker; also, the new static method is functionality that I added and is not present in the existing Color APIs)
final class TestCase: XCTestCase {
func testBanana() {
XCTAssertEqual(Color.banana, Color.new(from: "FEFC78")!)
}
func testAlexsColor() {
XCTAssertEqual(Color.alexsColor, Color.new(from: "0432FF")!)
}
func testMaximumPowerColor() {
XCTAssertEqual(Color.maximumPower, Color.new(from: "FF2600")!)
}
func testLongNameColor() {
XCTAssertEqual(Color.reallyLongNameThatJustKeepsGoingOnAndOnAndOnAndOn, Color.new(from: "AAA000"))
}
}
Here is an example error message that I get when I run the test:
testBanana(): XCTAssertEqual failed: ("NamedColor(name: "Banana", bundle: Optional(NSBundle </Users/trevorhafner/Library/Developer/Xcode/DerivedData/TransportBase-cbagdabrompfzofwkimswvlsincu/Build/Products/Debug/TransportBaseTests.xctest/Contents/Resources/TransportBase_TransportBaseTests.bundle> (not yet loaded)))") is not equal to ("#FEFC78FF")
Here is the autogenerated code that my Swift Package Plugin creates:
#if canImport(SwiftUI)
import SwiftUI
import Foundation
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public extension Color {
static let banana = Color("Banana", bundle: .module)
static let alexsColor = Color("Alex's Color", bundle: .module)
static let reallyLongNameThatJustKeepsGoingOnAndOnAndOnAndOn = Color("really long name that just keeps going on and on and on and on", bundle: .module)
static let maximumPower = Color("Maximum Power", bundle: .module)
}
#endif
Does anyone know how to somehow instruct the bundle or the Color to load such that the comparison can be made correctly between the two colours?
My tests fail with "Restarting after unexpected exit, crash, or test timeout". This is what I have so far established:
Does only happen when building with xcodebuild (14.3) but not when building with Xcode (14.3)
Tests that are failing are in a .testTarget within a local swift package and part of a test plan together with tests that are in subprojects
there are no crashlogs, so likely these tests are not crashing
with Xcode 14.2 there are no problems whatsoever (xcodebuild or Xcode)
Any ideas on how to debug this any further?
Best Roddi
Issue: When I click run unit tests the tests get 'stuck' and in the top bar is says "Testing..." and never completes - I even left it for an hour.
I have created new projects with no code written and the same thing happens.
I have deleted and re-downloaded code as well.
Current Xcode: 14.3
I don't believe it's a project issue since I have tried multiple but rather something with Xcode.
and my CPU % for Xcode shoots to 365+ when this is happening. I have a M1 Max with 64GB.
Any help would be appreciated.
I get this error from time to time in UI tests when they are run on CI. Any ideas what might be causing this error?
The documentation states that Xcode Cloud comes with support for git lfs (https://developer.apple.com/documentation/xcode/source-code-management-setup) but when I run my unit tests in Xcode Cloud, which have many images which are stored in git lfs, the tests all fail because they don't have the images.
How do I get Xcode Cloud to fetch git lfs images?
Thanks
I'm new to Xcode cloud - working with a Mac OS app, build is working great. Now I am trying to add a Test action; the testing target builds but won't run, and the error indicates it can't find the testing bundle in the expected build output. There's also mention of a code signing error, but I have automatic code signing enabled with the same settings on test target as the app.
I am only running the unit test (XCTest) scheme, not the UI tests. When I run it locally from the IDE it works fine, either selecting the test scheme explicitly or as the test step of the app scheme.
I notice the XCTest target's scheme setup uses Debug builds and expects the test output to be in the Debug .app bundle, I thought perhaps that was the problem (in case only the release app bundle actually gets built in the Xcode Cloud environment). So I created a duplicate scheme and set the build targets to Release - again I can run this fine locally (after creating a release build), but it fails with the same error in Xcode cloud.
I also tried changing the code signing certificate from "Development" to "Sign to run locally" to see if that made a difference, but I get the same error. (It's using my developer account Team, and "Automatically manage signing".)
Can anyone relate the proper way to set up an XCTest scheme so that the tests will actually run in a Mac OS Xcode Cloud workflow? I'm using Xcode 14.0.1.
Here's the full error output, with [AppName] and [TestTargetName] substituted for the actual:
[AppName] (....) encountered an error (Failed to load the test bundle. If you believe this error represents a bug, please attach the result bundle at /Volumes/workspace/resultbundle.xcresult. (Underlying Error: The bundle “[TestTargetName]” couldn’t be loaded. The bundle couldn’t be loaded. Try reinstalling the bundle. dlopen(/Volumes/workspace/TestProducts/Debug/[AppName].app/Contents/PlugIns/[TestTargetName].xctest/Contents/MacOS/[TestTargetName], 0x0109): tried: '/Volumes/workspace/TestProducts/Debug/[TestTargetName]' (no such file), '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/[TestTargetName]' (no such file), '/Volumes/workspace/TestProducts/Debug/[AppName].app/Contents/PlugIns/[TestTargetName].xctest/Contents/MacOS/[TestTargetName]' (code signature in <....> '/Volumes/workspace/TestProducts/Debug/[AppName].app/Contents/PlugIns/[TestTargetName].xctest/Contents/MacOS/[TestTargetName]' not valid for use in process: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?))))
Thanks!
Hi everybody,
given the following case using SwiftUI:
Button("testButton", action: noop)
.accessibilityRepresentation{representation: {
Slider(value: $sliderData.sliderValue)
})
.accessibilityIdentifier("testSlider")
I'm trying to control the slider using XCUITest via slider.adjust(toNormalizedSliderPosition: 0.2)
and receive the following error message:
Failed: Unable to get expected attributes for slider, found {
"XC_kAXXCAttributeMaxScrubberPosition" = {
X = 0;
Y = 0;
};
"XC_kAXXCAttributeMinScrubberPosition" = {
X = 0;
Y = 0;
};
Similarly, print (slider.normalizedSliderPosition) leads to the error message "Failed to determine current position of slider "0 %".
Is there a way to set and read the value of accessibilityRepresentation-Sliders with XCUITest?
Thanks!