Getting iOS Simulator UDID from tests

Sometimes it can be useful to have the UDID of the iOS simulator handy for automation purposes. Let’s learn how to extract it within XCTest.
Right off the boat 🤿
import XCTest
class SampleTest: XCTestCase {
func testSimulatorUDID() {
let env = ProcessInfo.processInfo.environment
let udid = env["SIMULATOR_UDID"] ?? ""
XCTAssertNotEqual(udid, "")
}
}
- Open an
Xcode
project - Create a test file
- Fill it with the code above
- Run it on any iOS Simulator
- Enjoy 🤠