{"id":16021447,"url":"https://github.com/orchetect/xctestutils","last_synced_at":"2025-10-12T13:46:46.343Z","repository":{"id":63919619,"uuid":"460193479","full_name":"orchetect/XCTestUtils","owner":"orchetect","description":"Useful XCTest extensions for Swift","archived":false,"fork":false,"pushed_at":"2023-06-27T21:44:59.000Z","size":42,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-01T16:07:49.935Z","etag":null,"topics":["ios","ios-swift","macos","macosx","swift","swiftui","test","testing","tvos","watchos","xcode","xctest","xctestcase"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orchetect.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"orchetect"}},"created_at":"2022-02-16T22:05:12.000Z","updated_at":"2023-04-21T05:09:54.000Z","dependencies_parsed_at":"2024-10-08T18:14:27.362Z","dependency_job_id":null,"html_url":"https://github.com/orchetect/XCTestUtils","commit_stats":{"total_commits":25,"total_committers":1,"mean_commits":25.0,"dds":0.0,"last_synced_commit":"e357a7ce3aa90c4819c8170b93f917b30b749566"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orchetect%2FXCTestUtils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orchetect%2FXCTestUtils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orchetect%2FXCTestUtils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orchetect%2FXCTestUtils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orchetect","download_url":"https://codeload.github.com/orchetect/XCTestUtils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284917,"owners_count":20913691,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","ios-swift","macos","macosx","swift","swiftui","test","testing","tvos","watchos","xcode","xctest","xctestcase"],"created_at":"2024-10-08T18:04:20.404Z","updated_at":"2025-10-12T13:46:46.331Z","avatar_url":"https://github.com/orchetect.png","language":"Swift","funding_links":["https://github.com/sponsors/orchetect"],"categories":[],"sub_categories":[],"readme":"# XCTestUtils\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Forchetect%2FXCTestUtils%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/orchetect/XCTestUtils) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Forchetect%2FXCTestUtils%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/orchetect/XCTestUtils) [![Xcode 13-16](https://img.shields.io/badge/Xcode-13–16-blue.svg?style=flat)](https://developer.apple.com/swift) [![License: MIT](http://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)](https://github.com/orchetect/XCTestUtils/blob/main/LICENSE)\n\nUseful XCTest utilities and extensions for test targets.\n\n## Overview\n\nCurrently, the library provides a small but useful set of XCTest related methods.\n\n## Wait for Expression\n\nTwo wait methods are implemented which may be useful in asynchronous testing scenarios where using XCTest expectations is not possible.\n\nThese methods allow for the continuous evaluation of an autoclosure expression with a timeout period in seconds. If the wait times out, it triggers a test fail. The evaluation is done every 10 milliseconds by default, but the interfal can be overridden with a custom polling period.\n\n```swift\n// wait for expression:\n// useful for non-equatability tests or tests where the test value\n// is not required to be logged in failure log messages\n// (akin to XCTAssertTrue)\nwait(for: x \u003e 10, timeout: 1.5)\nwait(for: x \u003e 10, timeout: 1.5, \"Description of waiter\")\n\n// closures can also be used for more complex expressions\nwait(for: {\n    let x = a + b\n    let y = check ? 5 : 10\n    return x == y\n}, timeout: 1.5)\n```\n\n```swift\n// wait for equality:\n// useful where the test value is required to be logged in failure log messages\n// (akin to XCTAssertEqual)\nwait(for: x, equals: 10, timeout: 1.5)\nwait(for: x, equals: 10, timeout: 1.5, \"Description of waiter\")\n\n// closures can also be used for more complex expressions\nwait(for: {\n    let x = a + b\n    return x \u003e 10\n}, equals: {\n    #if os(macOS)\n        10\n    #else\n        15\n    #endif\n}, timeout: 1.5)\n```\n\n### General Wait\n\nA generic non-blocking wait method is also provided:\n\n```swift\nwait(sec: 1.5) // seconds\n```\n\n### UI Testing\n\nA small assortment of throwing wrappers for `XCUIElement` methods are implemented.\n\n`waitForExistence(timeout:) -\u003e Bool` wrapped in a throwing method:\n\n```swift\nlet okButton = try await app\n    .buttons[\"OK\"]\n    .waitForExistence(throwingTimeout: 2.0)\n\nawait okButton.click()\n```\n\n`waitForNonExistence(timeout:) -\u003e Bool` wrapped in a throwing method:\n\n```swift\nlet okButton = await app.buttons[\"OK\"].firstMatch\ntry await okButton.waitForNonExistence(throwingTimeout: 2.0)\n```\n\n`wait(for:toEqual:timeout:) -\u003e Bool` wrapped in a throwing method:\n\n```swift\nlet okButton = await app.staticTexts[\"Idle\"].firstMatch\ntry await okButton.wait(for: \\.label, toEqual: \"Active\", throwingTimeout: 2.0)\n```\n\n## Installation: Swift Package Manager (SPM)\n\n### Dependency within an Application\n\n1. Add the package to your Xcode project's test target(s) using `https://github.com/orchetect/XCTestUtils` as the URL.\n\n2. Import the module in your test files where needed.\n\n   ```swift\n   import XCTest\n   import XCTestUtils\n   ```\n\n### Dependency within a Swift Package\n\n1. Add the dependency in your `Package.swift` file:\n\n   ```swift\n   dependencies: [\n       .package(url: \"https://github.com/orchetect/XCTestUtils\", from: \"1.1.2\")\n   ],\n   ```\n\n## Usage\n\nImport the module in test files where needed.\n\n```swift\nimport XCTest\nimport XCTestUtils\n```\n\n## Documentation\n\nThis README serves as basic documentation.\n\nAll methods have inline help explaining their purpose and basic usage examples.\n\n## Requirements\n\nMinimum system requirements for testing: Xcode 13 or higher on macOS 11.3 or higher\n\n## Author\n\nCoded by a bunch of 🐹 hamsters in a trenchcoat that calls itself [@orchetect](https://github.com/orchetect).\n\n## License\n\nLicensed under the MIT license. See [LICENSE](https://github.com/orchetect/XCTestUtils/blob/master/LICENSE) for details.\n\n## Community \u0026 Support\n\nPlease do not email maintainers for technical support. Several options are available for issues and questions:\n\n- Questions and feature ideas can be posted to [Discussions](https://github.com/orchetect/XCTestUtils/discussions).\n- If an issue is a verifiable bug with reproducible steps it may be posted in [Issues](https://github.com/orchetect/XCTestUtils/issues).\n\n## Contributions\n\nContributions are welcome. Posting in [Discussions](https://github.com/orchetect/XCTestUtils/discussions) first prior to new submitting PRs for features or modifications is encouraged.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forchetect%2Fxctestutils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forchetect%2Fxctestutils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forchetect%2Fxctestutils/lists"}