xctest

Why should I use a separate test target for running XCTests and how should I do that?

时光怂恿深爱的人放手 提交于 2019-12-10 13:59:05
问题 I once asked a question related to XCTests. And in one of the answers I was told that it is a common practice to use a separate test target (other than the main app) when running unit tests (at least, in iOS development). I tried to find some sources about it, but I couldn't I understand, that it is probably a best practice, so I would really like to understand it. Could someone explain to me why is it important, what benefits do I get from it and how should I go about doing it? Links to some

How write unit test for receiving nsnotification asynchronous?

送分小仙女□ 提交于 2019-12-10 13:47:33
问题 I call rest web servic with completion handler and if succeed I send NSNotification. The problem is how to write unit test to assert that the notification is sent in case of success. Any help will be appreciated. 回答1: You can add an expectation for the notification: expectationForNotification("BlaBlaNotification", object: nil) { (notification) -> Bool in // call the method that fetches the data sut.fetchData() waitForExpectationsWithTimeout(5, handler: nil) But personally I would split this

XCTestCase waitForExpectationsWithTimeout:handler: throwing EXC_BAD_ACCESS when expectation is not fulfilled

南笙酒味 提交于 2019-12-10 12:56:47
问题 I am testing an asynchronous call using XCTestExpectation. The following code works(the test succeeds) when the completionHandler is executed before the given 1 second timeout. func test__async_call() { // prepare let sut = ClassToTest() let expectation: XCTestExpectation = self.expectationWithDescription(nil) // test sut.methodToTestWithCompletionHandler() { () -> () in expectation.fulfill() } // verify self.waitForExpectationsWithTimeout(1, handler: nil) } However, if the completionHandler

Manipulate app permissions on iOS 8 simulator

孤人 提交于 2019-12-10 12:06:56
问题 Same question as this one, but for iOS 8. While running xctests, how can I make sure permissions are granted/denied programmatically? Is the same TCC.db used? If so, as there are no $HOME/Library/Application Support/iPhone Simulator/8.x directories, where has it moved to? 回答1: Thanks to username tbd, the TCC.db is still in use, but is now located at $HOME/Library/Developer/CoreSimulator/Devices/$DEVICEID/data/Library/TCC/ Schema of the "access" table is the same. NSArray *paths =

API violation - multiple calls made to -[XCTestExpectation fulfill]

安稳与你 提交于 2019-12-10 03:06:11
问题 I'm writing one of my first integration tests in Swift. I'm trying to check if an image exists at a particular url. I want to perform a head request and check the response's status code. I keep getting the error: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'API violation - multiple calls made to -[XCTestExpectation fulfill]. I've tried making the expectation a weak variable. I have the following code/test: func testAndroidImagesExist() { weak var

Any way to automate SFSafariViewController in UI tests?

南笙酒味 提交于 2019-12-10 02:11:47
问题 Is there any way to automate SFSafariViewController? I like the Xcode 7 UI test feature, but it seems it does not support SFSafariViewController automation. Some of the UI flows I am testing require a web browser so the app uses SFSafariViewController to make it safer vs a web view. 回答1: If it's similar to launching extensions (currently broken with direct interactions), try tapping the screen at the point where the element you're looking for is: Example of tapping an action sheet which

Mocking a static class method in a swift unit test in a swifty way?

自闭症网瘾萝莉.ら 提交于 2019-12-10 01:58:49
问题 I'm a seasoned Objective-c programmer but I can't say the same for Swift, I'm having a hard time unit testing a class in swift without using frameworks like OCMock. The Problem : I'm integrating Firebase into a mixed Objective-C/Swift project, and I need to configure it based on the build configuration of the app. I've written a Swift class for that (that will be used by the obj-c app delegate), however since the firebase framework is configured trough a static class method, precisely FIRApp

Asynchronous Performance Tests with XCTest

微笑、不失礼 提交于 2019-12-10 01:44:52
问题 I have started to explore the new XCTest APIs for asynchronous and performance testing. In isolation, the Apple examples from WWMC work well, but I have been unable to figure out how to combine them. The best I have been able to come up with is the following, but I receive the following error when it runs: API violation - call made to wait without any expectations having been set. XCTestExpectation *clsQueryReturnedExpectation = [self expectationWithDescription:@"clsQuery returned"];

XCUITest interact with a Notification Banner.

≡放荡痞女 提交于 2019-12-09 19:30:31
问题 Is it possible in XCUITest to validate that a notification banner is sent to the screen? I can add an accessibility identifier to the notification, but I am having a problem getting XCUITest to interact with it when the banner is ent to the screen. I know that XCUITest runs in a separate process from the app, but was wondeering if it was still possible to interact with the notification or is it beyond the scope of XCUITest? Thanks, 回答1: With Xcode 9 this is now possible. You can get access to

How can one use XCTAssertNil with optional structs?

点点圈 提交于 2019-12-09 15:49:20
问题 Update 3/23/2016 I just tested my original sample code below and it all compiles fine in XCode 7.3. Looks like XCTAssertNil was updated along the way to take an expression of type () throws -> Any? Therefore this question and answer may be no longer needed (except for a while with older versions of the compiler.) I'm writing my first unit tests in XCode with XCTest. I'm unsure how one can take advantage of XCTAssertNil as it seems to only compile when using certain types. It appears it will