I update my Xcode to latest 16.2. However I am unable to run the unit tests which were working fine when I used Xcode 15. Also I am using a CI/CD tools which has Xcode 15.3 and also using iOS 17.5 device to run unit tests and those are also working fine.
I am getting following 3 different types of errors when I try running tests.
Command SwiftCompile failed with a nonzero exit code
Command SwiftEmitModule failed with a nonzero exit code
PhaseScriptExecution failed with a nonzero exit code
Any help how I can fix this?
XCTest
RSS for tagCreate and run unit tests, performance tests, and UI tests for your Xcode project using XCTest.
Posts under XCTest tag
94 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
My SwiftUI app uses an Image with a tap gesture:
Image(systemName: "xmark.circle.fill")
.accessibilityIdentifier(kTextFieldClearButton)
.foregroundColor(.secondary)
.padding(.trailing, 6)
.onTapGesture {
dataSource.textFieldText = ""
}
In a UI test, I want to tap this image to execute its action:
let clearButton = app.images[kTextFieldClearButton]
clearButton.tap()
However the action is not executed.
I then set a breakpoint at clearButton.tap(), to execute lldb commands. Here are the results:
(lldb) p clearButton.isHittable
t = 439.54s Find the "TextFieldClearButton" Imag
(Bool) true
e
It is a little strange that "Image" has been interrupted by (Bool) true, but the image is hittable.
p clearButton.isAccessibilityElement
gives
(lldb) p clearButton.isAccessibilityElement
(Bool) false
I don't understand why this Image is no accessibility element. I thought, SwiftUI Views are by default accessible.
What can I do to make it accessible so that clearButton.tap() works as expected?
Let's say I have a local package Foo, Bar and Baz.
Foo has Bar and Baz as dependency and has test target,FooTests.
Below is the Package.swift manifest that describes package Foo.
import PackageDescription
let packages: [Package.Dependency] = [
.package(path: "../Bar"),
.package(path: "../Baz"),
]
let products: [Target.Dependency] = [
.product(name: "Bar", package: "Bar"),
.product(name: "Baz", package: "Baz"),
]
let package = Package(
name: "Foo",
platforms: [
.iOS(.v16),
],
products: [
.library(
name: "Foo",
targets: ["Foo"]
),
],
dependencies: packages,
targets: [
.target(
name: "Foo",
dependencies: products,
path: "Sources"
),
.testTarget(
name: "FooTests",
dependencies: [.target(name: "Foo")],
path: "Tests",
swiftSettings: swiftSettings
),
]
)
Bar and Baz is also local packages.
Due to the limitations of the project, Baz has sources with symbolic links instead of exact directories, and these sources are what FooTests will test.
If I run FooTests, test succeed with proper logs indicating that all test methods are run correctly, but test coverage says that Baz's coverage is 0% and there is no executable lines unlike the Bar which is not what be tested.
Is there any way to fix this problem?
I have an XCTest unit test that's running in an iOS host but with the My Mac (Designed For iPad) Target.
Enabling mergeable libraries causes two errors:
Symbol not found: _$s10Foundation3URLV9RVAPIPackE8isGCSURLSbvg
And "loading failed because of an error Error Domain=NSCocoaErrorDomain Code=3588" for the Test bundle because one of the frameworks that's supposed to be merged couldn't be loaded.
Disabling mergeable libraries fixes it. It also works with mergeable libraries enabled but with a regular simulator target. So not sure if I'm missing something or if I need to disable mergeable libraries now:/
Hi,
Could someone possibly tell me if it is accurate that Xcode Version 16.1 (16B40) is NOT compatible with iOS 18.1.1 and if so, when it will be?
Many TIA.
I try to do unit test for an ES system extension's code using Unit Testing Bundle.
the code tries to get NSEndpointSecurityMachServiceName in info.plist by [bundle objectForInfoDictionaryKey:] but failed.
I have added NSEndpointSecurityMachService to info.plist of Test Bundle, and I did check info.plist file in bundle, NSEndpointSecurityMachServiceName was listed there.
In Xcode Version 16.1
Create a new Project, choose Multiplatform, App
For testing system, choose XCTest and UI Tests
In the project, open the newly generated template Unit test file
Click either of the diamonds in the left margin (either to run the example test or the entire file)
Expected Result: Code compiles and then Runs the test/tests
Actual Result: Code compiles, but then never completes testing (the top status bar is stuck saying "Testing..." forever.)
Am I missing something?
Hi,
I have recently noticed a very-very annoying thing in my CI pipeline, that I managed to reproduce locally.
Using macOS Sonoma 14.7.1 and Xcode 15.4, running a test target from Terminal, the first run produces this output:
$ xcodebuild test -workspace [redacted].xcworkspace -scheme [redacted] -quiet
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, id:[redacted], name:My Mac }
{ platform:macOS, arch:x86_64, id:[redacted], name:My Mac }
{ platform:macOS, name:Any Mac }
Testing started
Test suite '[redacted]' started on 'My Mac - [redacted] (75944)'
Test case '[redacted].[redacted]()' passed on 'My Mac - [redacted] (75944)' (0.001 seconds)
Test case '[redacted].[redacted]()' passed on 'My Mac - [redacted] (75944)' (0.001 seconds)
2024-11-29 19:31:02.311 xcodebuild[75908:47784216] [MT] IDETestOperationsObserverDebug: 1.380 elapsed -- Testing started completed.
2024-11-29 19:31:02.311 xcodebuild[75908:47784216] [MT] IDETestOperationsObserverDebug: 0.000 sec, +0.000 sec -- start
2024-11-29 19:31:02.311 xcodebuild[75908:47784216] [MT] IDETestOperationsObserverDebug: 1.380 sec, +1.380 sec -- end
so the test actually completes, but the process does not end, because I get a popup that
“Terminal.app” would like to access data from other apps.
Removing the "App Sandbox" entitlement immediately alleviates this problem, but it would be very silly to do so because of unit tests.
This ultimately means that whenever we use a new device or include a new project or test target, this popup comes up. Very undesirable for CI servers (especially if the servers are ephemeral virtual machines created for the current job).
Is there a permanent solution that disables this popup for test runs?
Sorry if this question is too vague, however I've tried this multiple times and see the same result. I'm pretty sure I'm doing something wrong, but don't know what.
I have a Multiplatform (iOS and macOS) project that builds, and runs
I add a new target of type Unit Test Bundle
I click the diamond in the margin beside the XCTestCase declaration at the top of the new Test file
The target project builds, then Xcode says 'Testing...' and it stays like this forever.
I've also tried creating a new scheme that targets the target created in the above steps. attempting to run my tests behaves the same. The top status bar will get stuck saying 'Testing...' and never get anywhere.
I'm pretty sure this is something basic.
thanks, in advance for any guidance.
Mike
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."
I have latest version Xcode-15.1 & Mac-os version Sonoma-14.3.1 - while running particularly UITest target Xcode not launching the simulator, even after build succeed & test's completed without any errors.
I tried cleaning project, re-starting Xcode, restarting system(Mac) - no luck
It would be helpful if I get any suggestion on resolving the issue.
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
I'm trying to run an xctest bundle, built for catalyst, with xcrun.
i.e.
xcrun xctest path_to_my_test.xctest
It fails, complaining that:
The bundle "MyBundle" couldn't be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.....but incompatible platform (have 'MacCatalyst', need 'macOS')
So it seems like because I'm not executing it in a sim it wants the bundle to be a macOS bundle. But I would have thought it would be possible to run a Mac Catalyst target directly on a macOS host the same as a native macOS test target. Is this not possible?
Our use case is that we need to run a CLI script (on Mac) to set up backend configuration before each test case (UI test on real iOS device). The setup logic is test specific, so using pre-build scripts is not an option.
Is this support in any way or what are best practices around such a setup?
Ideally, we would still be able to execute the tests from within Xcode.
Our use case is that we need to run a CLI script (on Mac) to set up some backend configuration for a UITest that then runs on iOS (simulator or actual device). The setup logic is test specific so using pre-build scripts is not a an option. Is that support in any way or what would be alternatives to go about this.
We have been trying to migrate screens that were developed using UITool Kit to SwiftUI. In the process we have some screens that have SwiftUI embedded inside the UITool kit view. Our developers have defined accessibility ids for all elements in these views and these are inspectable using the native iOS xcode inspector. However when i try inspecting it with the appium inspector i get an empty list with no elements in the hierarchy tree. Attaching a screenshot of the element when inspecting through the native xcode accessibility inspector,
Attaching a screenshot of the same screen when inspected through the appium inspector,
Also tried printing the XCTest UI dump using appium method,
`driver().executeScript("mobile:source", Map.ofEntries(Map.entry("format","description")))
The UI tree i get is the same that i get when inspecting through the appium inspector.
Requesting support from the Apple team based on this ticket, [https://github.com/appium/appium/issues/20759)
While I was recently profiling some code from a Swift library, I noticed that XCTest added in signposts for the measurement tests, which I found really helpful to "home in" on the code I wanted to profile digging around in the stack trace.
I tried to add my own signposts to provide just a bit of my own markers in there, but while it compiles and profiles equivalently, the signposts just aren't showing up. This is with Xcode 16.1, macOS Sequoia (15.1) and a swift library, using XCTest and profiling within one of the unit tests.
Is there something in this sequence that doesn't allow the library to set up signposts and have instruments collect them?
The flow I'm using:
import os
let subsystem = "MyLibrary"
class MyClass {
let logger: Logger = .init(subsystem: subsystem, category: "fastloop")
let signposter: OSSignposter
init() {
signposter = OSSignposter(logger: logger)
}
func goFast() {
let signpostId = signposter.makeSignpostID()
let state = signposter.beginInterval("tick", id: signpostId)
// ... do a bunch of work here - all synchronous
signposter.endInterval("tick", state)
}
}
Is there something I'm doing incorrectly in using this API, or not enabling to allow those signposts to be collected by the profiler?
I do see the signposts that XCTests injects into the system, just not any of the ones I'm creating.
In WWDC23: Fix failures faster with Xcode test reports, the presenter showed off an Xcode feature called Automation Explorer, that allows playback of a screen recording corresponding to an XCUITest.
For the life of me, I have not been able to find out how to enable/use this feature in Xcode 16. I am using Test Plans and have set the UI Testing configuration settings for Automatic Screen Capture to On, and keep all and Preferred Capture Format to Video, but am not seeing any screen recordings being produced after running the tests. Am I doing something wrong?
I have different versions of my iOS App (written in SwiftUI). The app on the store, the App Clip, and one or two next version apps not yet released (e.g. A/B comparison). All good. But now I've started creating UI and Unit tests and I'm confused about how to get this working.
Each build target has its own scheme. And in that scheme I have a Test plan for that target. E.g. The App Clip scheme has an App Clip test plan.
Since all the app variants are very similar, I only have one set of unit tests and one set of UI tests so each test plan includes the same unit test target and the UI test target.
Problem: When I selected a scheme (e.g. for the App Clip) and ran the tests, it turned out that all the tests ran for another build target, not the target of the scheme. I think this might be because within the definition of the test target there's a field specifying the host application. I.e. the build target.
Question: How can I set up my project so that the test plan uses the relevant target build?
Or do I have to duplicate all the test targets (one for each target)?
Or do I have to manually change each test target before running it for a particular build target?
We are building an iOS app that connects to a device using Bluetooth. To test unhappy flow scenarios for this app, we'd like to power cycle the device we are connecting to by using an IoT power switch that connects to the local network using WiFi (a Shelly Plug-S).
In my test code on iOS13, I was able to do a local HTTP call to the IP address of the power switch and trigger a power cycle using its REST interface. In iOS 14 this is no longer possible, probably due to new restrictions regarding local network usage without permissions (see: https://developer.apple.com/videos/play/wwdc2020/10110 ).
When running the test and trying a local network call to the power switch in iOS14, I get the following error:
Task <D206B326-1820-43CA-A54C-5B470B4F1A79>.<2> finished with error [-1009] Error Domain=NSURLErrorDomain Code=-1009 "The internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x2833f34b0 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <D206B326-1820-43CA-A54C-5B470B4F1A79>.<2>, _NSURLErrorRelatedURLSessionTaskErrorKey=("LocalDataTask <D206B326-1820-43CA-A54C-5B470B4F1A79>.<2>"), NSLocalizedDescription=The internet connection appears to be offline., NSErrorFailingURLStringKey=http://192.168.22.57/relay/0?turn=on, NSErrorFailingURLKey=http://192.168.22.57/relay/0?turn=on, _kCFStreamErrorDomainKey=1}
An external network call (to google.com) works just fine in the test.
I have tried fixing this by adding the following entries to the Info.plist of my UI test target:
<key>NSLocalNetworkUsageDescription</key>
<string>Local network access is needed for tests</string>
<key>NSBonjourServices</key>
<array>
<string>_http._tcp</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
However, this has no effect.
I have also tried adding these entries to the Info.plist of my app target to see if that makes a difference, but it doesn't. I'd also rather not add these entries to my app's Info.plist, because the app does not need local network access. Only the test does.
Does anyone know how to enable local network access during an iOS UI test in iOS14?