How to select a picker view item in an iOS UI test in Xcode?

As noted in the question’s update, Xcode 7 Beta 6 added support for interacting with pickers. The newly added method -adjustToPickerWheelValue: should be used to select items on a UIPickerView. let app = XCUIApplication() app.launch() app.pickerWheels.element.adjustToPickerWheelValue(“Yellow”) Here’s a GitHub repo with a working example. And some more information in a blog post I wrote.

How to run one-time setup code before executing any XCTest

TL;DR: As stated here, you should declare an NSPrincipalClass in your test-targets Info.plist. Execute all the one-time-setup code inside the init of this class, since “XCTest automatically creates a single instance of that class when the test bundle is loaded”, thus all your one-time-setup code will be executed once when loading the test-bundle. A bit … Read more

Xcode 7 UI Testing: how to dismiss a series of system alerts in code

Xcode 7.1 Xcode 7.1 has finally fixed the issue with system alerts. There are, however, two small gotchas. First, you need to set up a “UI Interuption Handler” before presenting the alert. This is our way of telling the framework how to handle an alert when it appears. Second, after presenting the alert you must … Read more

When do app sources need to be included in test targets?

I spent some time figuring this out. If you read this documentation you find that Xcode has two modes for running tests. Logic Tests and Application Tests. The difference is Logic tests build their own target with your Classes and symbols built right in. The resulting executable can be run in the simulator and reports … Read more

How can I get XCTest to wait for async calls in setUp before tests are run?

Rather than using semaphores or blocking loops, you can use the same waitForExpectationsWithTimeout:handler: function you use in your async test cases. // Swift override func setUp() { super.setUp() let exp = expectation(description: “\(#function)\(#line)”) // Issue an async request let data = getData() db.overwriteDatabase(data) { // do some stuff exp.fulfill() } // Wait for the async … Read more

XCTAssertEqual fails to compare two string values?

From the documentation of XCTAssertEqual: Generates a failure when a1 is not equal to a2. This test is for C scalars, structs and unions. You should use XCTAssertEqualObjects (which uses isEqual: internally) or something like: XCTAssertTrue([[firstNickName initialsFromString] isEqualToString:expectedResult], @”Strings are not equal %@ %@”, expectedResult, [firstNickName initialsFromString]);

NSURL to file path in test bundle with XCTest

In fact, the [NSBundle mainBundle] when running a UnitTest is not the path of your app, but is /Developer/usr/bin, so this will not work. The way to get resources in a unit test is here: OCUnit & NSBundle In short, use: [[NSBundle bundleForClass:[self class]] resourcePath] or in your case: [[NSBundle bundleForClass:[self class]] resourceURL]

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)