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

XCTest Documentation

Posts under XCTest tag

182 Posts
Sort by:
Post not yet marked as solved
9 Replies
2.7k Views
Following moving to Xcode 13 from 12.5, we are seeing our test coverage reported at ~1%, with only a small number of tests being reported in line with previous xcode builds. Is this a know issue? Are there steps we can take to debug or mitigate this? Nothing of note identified within the build log. Xcode 13 Coverage: Xcode 12 Coverage:
Posted Last updated
.
Post not yet marked as solved
4 Replies
4.5k Views
Xcode version : Version 9.4.1 (9F2000)Currently I am testing an an app using Automation with XCTest Framework.I am running into a series of issues with the UI where the element says it is visible (exists) and isHittable (Both are true), but the next thing that shows up is an Assertion Failure. (Note: This doesn't happen for the same element everytime. Sometimes it works fine with one element and doesnt with the same element).Failed to determine hittability of "notification2:title" StaticText: Error copying attributes -25202I found this issue in earlier versions of Xcode too but the Assertion failure gave an error "Failure to determine hit point for the element".Thins that i have tried:-> Adding sleep before checking if the element is hittable or when tapping on the element.->Adding waitForExistenceWithTimeout before checking for the element or tapping on it.These didn't help me.Adding to the above, due to the nature of the app I can't test it on the simulator. I am testing it on a real device. And below is the log that i print before tapping or checking for the element. You can see element.exists and element.isHittable both return true but gives an Assertion failure.Checking for the element is visible and hittable before scrolling the parentElement. Element is Visible--YES, Element is hittable--YES
Posted
by vivek5605.
Last updated
.
Post not yet marked as solved
0 Replies
153 Views
Due to some of what we do with the Metal API in our iOS app, we are unable use Simulator for development / testing purposes. With the introduction of Apple Silicon, we are able to run/build to the "My Mac (Designed for iPad)" destination for our app. However, when we try running UI tests with that destination we get the message "Cannot test target <ui_test_target> on "My Mac": UI tests are not supported ..." Wondering if there's a way to run UI tests against the "My Mac (Designed for iPad)" destination?
Posted Last updated
.
Post not yet marked as solved
1 Replies
773 Views
UI Tests seem to be broken when run on an iPhone running iOS 15.4. Steps to reproduce: Create a fresh app project in Xcode 13.3 including UI tests Select an attached iPhone running iOS 15.4 Run the UI test testExample which only starts the app, nothing more. Restart the attached phone Try to run testExample again. Expectation: Test succeeds again Actual: When launching the app, XCTest is internally first trying to terminate the app and gets stuck. After 60s the tests fail. Logging (app id and home folder are removed for privacy reasons): TESTUITests-Runner[341:7025] Running tests... Test Suite 'Selected tests' started at 2022-03-17 14:53:36.855 Test Suite 'TESTUITests.xctest' started at 2022-03-17 14:53:36.855 Test Suite 'TESTUITests' started at 2022-03-17 14:53:36.856 Test Case '-[TESTUITests.TESTUITests testExample]' started. t = 0.00s Start Test at 2022-03-17 14:53:36.856 t = 0.07s Set Up t = 0.07s Open <app_id>.TEST t = 0.11s Launch <app_id>.TEST t = 0.11s Terminate <app_id>.TEST:269 <UserHome>/Workspace/TEST/TESTUITests/TESTUITests.swift:28: error: -[TESTUITests.TESTUITests testExample] : Failed to terminate <app_id>.TEST:269: Failed to terminate <app_id>.TEST:0 t = 60.29s Tear Down Test Case '-[TESTUITests.TESTUITests testExample]' failed (60.294 seconds). Test Suite 'TESTUITests' failed at 2022-03-17 14:54:37.150. Executed 1 test, with 1 failure (0 unexpected) in 60.294 (60.294) seconds Test Suite 'TESTUITests.xctest' failed at 2022-03-17 14:54:37.150. Executed 1 test, with 1 failure (0 unexpected) in 60.294 (60.295) seconds Test Suite 'Selected tests' failed at 2022-03-17 14:54:37.151. Executed 1 test, with 1 failure (0 unexpected) in 60.294 (60.296) seconds If I manually start the app once, then the UI tests will run again afterwards for a while (including restarting the app). At some point they get stuck again and we are not sure why, yet. This makes it really hard to run tests in our CI because we can't keep sending someone into the server room to manually start the app... Has anybody else encountered this and found a solution? It works fine on iOS 15.1.1.
Posted
by Infinite.
Last updated
.
Post not yet marked as solved
1 Replies
553 Views
Using WDA from Appium to automate XCUI Tests Machine: Mac OS 11.4 Device: iPad 14.6 Xcode : Version 12.5 (12E262) When WDA is unable to take screenShot hence not able to automate UI Xcode Logs: 2021-06-24 14:15:26.642040+0530 WebDriverAgentRunner-Runner[2474:850794] Getting the most recent active application (out of 1 total items) t = 5975.92s Requesting snapshot of accessibility hierarchy for app with pid 2491 2021-06-24 14:15:28.747873+0530 WebDriverAgentRunner-Runner[2474:850794] Getting the most recent active application (out of 1 total items) 2021-06-24 14:15:28.803031+0530 WebDriverAgentRunner-Runner[2474:850794] Getting the most recent active application (out of 1 total items) 2021-06-24 14:15:28.806114+0530 WebDriverAgentRunner-Runner[2474:850794] The following attributes were requested to be included into the XML: {( FBHeightAttribute, FBAccessibleAttribute, FBValueAttribute, FBVisibleAttribute, FBWidthAttribute, FBEnabledAttribute, FBTypeAttribute, FBYAttribute, FBLabelAttribute, FBIndexAttribute, FBXAttribute, FBNameAttribute )} 2021-06-24 14:15:28.806528+0530 WebDriverAgentRunner-Runner[2474:850794] Waiting up to 2s until com.carriertransicold.containerLINK is in idle state (including animations) t = 5978.08s Wait for com.carriertransicold.containerLINK to idle t = 5978.09s Requesting snapshot of accessibility hierarchy for app with pid 2491 2021-06-24 14:18:00.830823+0530 WebDriverAgentRunner-Runner[2474:850794] Cannot take a snapshot with attribute(s) ( "XC_kAXXCAttributeElementBaseType", "XC_kAXXCAttributeHasNativeFocus", "XC_kAXXCAttributeTruncatedValue", "XC_kAXXCAttributeViewControllerTitle", "XC_kAXXCAttributeUserTestingElements", "XC_kAXXCAttributeAutomationType", "XC_kAXXCAttributeBannerIsStickyAttribute", "XC_kAXXCAttributeIdentifier", "XC_kAXXCAttributeTraits", "XC_kAXXCAttributeFrame", "XC_kAXXCAttributeVerticalSizeClass", "XC_kAXXCAttributeViewControllerClassName", "XC_kAXXCAttributeIsUserInteractionEnabled", "XC_kAXXCAttributeLabel", "XC_kAXXCAttributeURL", "XC_kAXXCAttributeParent", "XC_kAXXCAttributeHorizontalSizeClass", "XC_kAXXCAttributePlaceholderValue", "XC_kAXXCAttributeElementType", "XC_kAXXCAttributeIsVisible" ) of 'XCUIElementTypeAny' after 600.00 seconds 2021-06-24 14:18:00.831124+0530 WebDriverAgentRunner-Runner[2474:850794] This timeout could be customized via 'customSnapshotTimeout' setting 2021-06-24 14:18:00.831248+0530 WebDriverAgentRunner-Runner[2474:850794] Internal error: XCTPerformOnMainRunLoop work timed out after 60.0s 2021-06-24 14:18:00.831459+0530 WebDriverAgentRunner-Runner[2474:850794] Falling back to the default snapshotting mechanism for the element 'XCUIElementTypeAny' (some attribute values, like visibility or accessibility might not be precise though) 2021-06-24 14:20:30.865277+0530 WebDriverAgentRunner-Runner[2474:850794] Cannot retrieve element attribute(s) ( "XC_kAXXCAttributeIsElement" ). Original error: Error Domain=com.apple.dt.xctest.automation-support.error Code=11 "Accessibility error kAXErrorIPCTimeout from AXUIElementCopyMultipleAttributeValues for 2016" UserInfo={accessibility-error=-25216, NSLocalizedDescription=Accessibility error kAXErrorIPCTimeout from AXUIElementCopyMultipleAttributeValues for 2016} Errors are displayed
Posted Last updated
.
Post marked as solved
1 Replies
821 Views
Hi community, my existing ui-tests did test push-notification interactions. Since upgrading to Xcode 13 those tests fail when tapping a by the generic tap via XCUIApplication(bundleIdentifier: "com.apple.springboard").otherElements["Notification"].firstMatch.tap() this is the error I get *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil (NSInvalidArgumentException) actually the push notification is visible and can be queried in the debug console. just tapping it, crashes the test. I`m testing this with a real device (iPhone X, iOS 15). Testing on a iOS 14 device still works. Did anyone else face this problem or solve it? Thanks you
Posted Last updated
.
Post not yet marked as solved
2 Replies
1k Views
Hi Everyone. I'm trying to use Accessibility Inspector thats included with Xcode 13.3 and it fails to identify UI elements with Target mode... basically the entire iOS simulator is a green/unreadable element. Besides the fact that is hangs a lot is this tool completely broken now? If I try to run an audit it just throws the warning: Element has no description This SimulatorKit.SimDisplayRenderableView is missing useful accessibility information. Note that no matter what app I try to inspect, it always fails, it also fails when I try to inspect the springboard / home screen. It worked fine in 13.2.1 and now its completely broken.
Posted
by andyz.
Last updated
.
Post not yet marked as solved
0 Replies
171 Views
The problem On iOS 15 was changed the view for notifications on the Notification center. All tried operations with XCUITest are not working to expand it by force touch. Environment Xcode 13.3; iOS 15.4; iPhone 8 simulator; macOS Monterey 12.2.1. Details For example, we received any notification in the notification center. Manually we can expand it by force touch ( NB! Should be on: Simulator->I/O -> Touch pressures -> Use trackpad force). But there are no any ways to do this by XCUITest methods. Seem like not enough press is performed for all of them. Could this issue be fixed somehow?
Posted
by vkuhi.
Last updated
.
Post not yet marked as solved
1 Replies
187 Views
I have the following protocol that a NetworkEngine conforms to: protocol NetworkEngineProtocol { func request&amp;lt;T: Decodable&amp;gt;(from endpoint: Endpoint) async throws -&amp;gt; T } This protocol is passed as a dependency into a custom ViewModel and I want to unit test the request method of the ViewModel, that itself calls the dependency request method. class ViewModel: ViewModelProtocol { var passthrough: PassthroughSubject&amp;lt;[SomeProperty], Never&amp;gt; = PassthroughSubject&amp;lt;[SomeProperty], Never&amp;gt;() private let networkEngine: NetworkEngineProtocol init(networkEngine: NetworkEngineProtocol) { self.networkEngine = networkEngine } func request() { Task { do { let model = try await networkEngine.request(from: .messages()) as CustomModel // ... do more stuff passthrough.send(someValue) // would want to test this } catch let err as NetworkEngineErrors { // ... error handling } } } } struct CustomModel: Decodable { let message: [String] let status: String } In order to Unit Test this method, I'd have to create a Mock class, that conforms to the NetworkEngineProtocol. Something like: class MockNetworkProtocol: NetworkEngineProtocol { init() {} func request&amp;lt;T&amp;gt;(from endpoint: Endpoint) async throws -&amp;gt; T where T : Decodable { // how to mock this? } } What's the best way to do this? How can I mock the request method of the NetworkEngine? Thanks
Posted Last updated
.
Post not yet marked as solved
0 Replies
168 Views
I would like to create some UI tests for an App Clip. But when adding the UI Test target, I am unable to select the app clip target as the target to be tested (It's greyed out). The only target I can add is the "real" app. Any suggestions? Isn't it possible, or do I need to configure it somehow?
Posted Last updated
.
Post not yet marked as solved
0 Replies
204 Views
Hello, We are experiencing failing UI Tests on M1 devices (Xcode 13.3.1) while they pass well on Intel devices. The most common errors are: App stucks on splashcreen resulting in xctassert timeout Scrolling is not working properly (like there is no deceleration) resulting in wrong screen position and not found elements Notes: Simulator is running without Rosetta We have to exclude arm64-simulator arch support because of third party libraries Has anyone encountered such a problem? Thanks!
Posted
by vladsh.
Last updated
.
Post not yet marked as solved
1 Replies
333 Views
I can't execute individual tests or test suits on XCode 13.1, I get this message: Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.000) seconds I can only execute the complete set of tests, is this a bug or am I missing something ?
Posted
by axel.mr.
Last updated
.
Post not yet marked as solved
10 Replies
2.1k Views
My app setup is similar to https://forums.developer.apple.com/thread/133495 - I have an app target, some frameworks and local Swift packages. I added the package tests to the test plan.Now, when "gather code coverage" is just "on" in the test plan, I get code coverage from the package targets. But when I selectively add only the targets I want (including the package targets), the package targets don't show up in the code coverage results at all.Gathering code coverage for all targets isn't really what I want, because that includes a lot of third-party code that I'm not interested in.
Posted
by Aurelian.
Last updated
.
Post not yet marked as solved
14 Replies
18k Views
I have a test I want to be able to run, but need to be able to handle different states, might be logged in, might have saved login credentials in Safari, etc.When a system dialog, "Safari Saved Password" in this case, comes up, I cannot seem to affect it any way, even though I have recorded a session that selectes "Not Now", the query actually fails to find the button.The Accessibility inspector shows the button existing about 3 levels down, but there doesn't seem to be a way I can find to access it. AXApplication AXWindow AXButtonIs there a way to get to this thing?Thanks!
Posted
by Monicker.
Last updated
.
Post not yet marked as solved
0 Replies
104 Views
It seems like there’s no access to many accessibility properties of UI elements exposed in XCUITest framework (XCUIElement). Specifically, I’m trying to test the accessibility hint (accessibilityHint) of an element, but unable to do that. Although this is what I'm missing right now, but in general there are more accessibility properties I'd like to be able to access: accessibilityTraits accessibilityLanguage accessibilityActivationPoint accessibilityPath Is there any way to do this using XCUITest framework? If not, why can't we access them if those are accessibility attributes? What am I missing here?
Posted
by AsafKorem.
Last updated
.
Post not yet marked as solved
0 Replies
92 Views
I'm trying to use this API in my UITest suite: https://developer.apple.com/documentation/xctest/xcuicoordinate/3551692-press press(forDuration:thenDragTo:withVelocity:thenHoldForDuration:) However, the holdDuration parameter has no affect and the action stops once the drag is finished (instead of keep holding the element). I've reproduced this error with a demo application, along with a reproductive UI test and videos: https://github.com/asafkorem/XCUITestHoldBugReproduction Also, I do not find any reasonable workaround for the problem. Thanks.
Posted
by AsafKorem.
Last updated
.
Post not yet marked as solved
0 Replies
400 Views
Hello, I was trying out the XCUI testing for watch OS with the new Xcode 12.5. However, I could not find any way to swipe left or right on a SwiftUI TabView. I tried swipeLeft() directly on the XCUIApplication, on the windows, on the TabView, but couldn't make it work. I also tried with the .fast option, but no difference. My question is, is the swiping supported for watchOs on XCUI Test yet? Thanks!
Posted
by gloyer.
Last updated
.
Post not yet marked as solved
0 Replies
129 Views
I want to perform a unit test that whether my AVPlayerLayer is successfully added as sublayer in my ViewController view . I want to make a separate ViewController for this.Is it possible to make a separate ViewController for Unit Test ?
Posted
by Unique_23.
Last updated
.
Post not yet marked as solved
1 Replies
648 Views
Starting from Xcode 12.4 (I think), failing unit tests in framework targets take about 5 seconds to complete. Successful tests complete almost instantly (as expected). For example, the following test:     func testExampleFailure() {         XCTFail()     } Takes 4.356 seconds to execute on my 2019 MacBook Pro: Test Case '-[FrameworkTests.FrameworkTests testExampleFailure]' failed (4.356 seconds). This seems to only affect unit tests in Framework targets (unit tests for App targets are unaffected). I have also tested this in fresh Framework template projects across multiple Macs, so it appears to be an Xcode bug. I'd hoped Xcode 13 would fix this issue, but it persists for me on Monterey. Perhaps someone could suggest a workaround?
Posted
by Lemontine.
Last updated
.
Post not yet marked as solved
0 Replies
217 Views
Hi I have a problem with these identifiers I applied it like this to the tabbar self.tabBar.accessibilityIdentifier = @"MyID"; and works!!! But for tabBarItem I've tried everything but it doesn't work it's always empty Called in viewDidLoad of my TabbarController self.tabBarItem.isAccessibilityElement = YES; [self.tabBarItem setIsAccessibilityElement:YES]; self.tabBarItem.accessibilityIdentifier = @"MyID"; self.tabBar.items[0].accessibilityIdentifier = @"MyID"; Nothing works. I always get empty Do you have any idea on how to implement the identifier I want for each single element of the tabbar? Thanks
Posted
by n3o999.
Last updated
.