xctest

Grant access to NAB programatically on iOS 7.0 Simulator

允我心安 提交于 2019-11-29 15:11:43
问题 Is it possible to grant access to the native address book (NAB) on iOS 7.0 Simulator programmatically? I am writing xctest Unit Tests that need write access to NAB. The unit tests are run on iOS 7.0 Simulator and are part of Continuous Integration process and doesn't involve any user interaction. Currently unless the user grants access explicitly via the “TestApp” Would like to Access Your Contacts alert, access to NAB is denied. 回答1: In the spirit of sharing I am going to answer my own

Swift TyphoonBlockComponentFactory Error in XCTest

人走茶凉 提交于 2019-11-29 14:19:27
i’m using Swift with Typhoon and Cocoapods. Everything worked well until i started to write an Integrationtest (according to the Typhoon-Example-App Test ) for my Typhoon component. I wanted to setup the TyphoonFactory in the Test setUp() method in the same way as i did in the AppDelegate . When i execute the test i always get a TyphoonBlockComponentFactory assertIsAssembly:] + 244: ERROR: MyApp.MyAssembly is not a sub-class of TyphoonAssembly error thrown by Typhoon (wich is using the kindOfClass method under the hood.) The same code is working perfectly in the AppDelegate and i can’t figure

How to unit-test NSFetchedResultsController in Swift

戏子无情 提交于 2019-11-29 14:15:16
问题 I have a Swift app that uses NSFetchedResultsController to fetch List objects from persistent store: let fetchedResultsController: NSFetchedResultsController = ... var error : NSError? fetchedResultsController.performFetch(&error) if let error = error { NSLog("Error: \(error)") } let lists: [List] = fetchedResultsController.fetchedObjects! as [List] NSLog("lists count = \(lists.count)") for list: List in lists { NSLog("List: \(list.description)") } and it works like expected, I am getting

iOS Unit Testing: Class is implemented in both

扶醉桌前 提交于 2019-11-29 10:55:41
I'm building an iOS 9 App with Swift 2 and Xcode 7. My app runs fine when deploying it to my phone but when I run any unit test, I get the following error message for a lot of classes: Class _TtC5<AppName>19<ClassName> is implemented in both /Users/<Username>/Library/Developer/CoreSimulator/Devices/<UUID>/data/Containers/Bundle/Application/<UUID</<AppName>.app/<AppName> and /Users/<Username>/<Path/To/Workspace>/DerivedData/<AppName>/Build/Products/Debug-iphonesimulator/<AppName>.xctest/<AppName>. One of the two will be used. Which one is undefined. Any ideas? Only add the test class to your

XCTAssertEqual error: (“3”) is not equal to (“3”)

无人久伴 提交于 2019-11-29 10:37:09
问题 NSMutableArray *arr = [NSMutableArray array]; [arr addObject:@"1"]; [arr addObject:@"2"]; [arr addObject:@"3"]; // This statement is fine. XCTAssertTrue(arr.count == 3, @"Wrong array size."); // This assertion fails with an error: ((arr.count) equal to (3)) failed: ("3") is not equal to ("3") XCTAssertEqual(arr.count, 3, @"Wrong array size."); What don't I understand about XCTAssertEqual? Why does the last assertion fail? 回答1: I have also had quite a bit of trouble with Xcode 5's tests. It

Unit testing Parse framework iOS

≯℡__Kan透↙ 提交于 2019-11-29 08:01:59
I am attempting to write unit tests for an iOS application which makes use of the Parse backend framework, and after much experimentation seem to be failing at writing successful unit tests. I have found a few posts on testing asynchronous code ( Testing asynchronous call in unit test in iOS ) and testing network calls, but am yet to find a way of testing calls to the Parse backend with async callbacks. To give an example, could anyone advise how I would test the following line of code: [PFUser saveUser:userModelMock withBlock:^(BOOL success, NSError *error) { }]; I am using OCMock and the

“XXX-Swift.h” file not found in test project

两盒软妹~` 提交于 2019-11-29 07:40:08
I'm trying to call a method of a NSObject subclass I have in the let's say "main" project within a method of a XCTestCase subclass in the test project. The NSObject subclass of the main project imports the "XXX-Swift.h" header file (I'm mixing Swift and Objective-C code). All works fine when I run the main project, but when I run the tests calling an object of that subclass, I get an error saying that the Swift header file in the import is not found. I guess I'm missing some settings in the test target, but I don`t find which... what should I check? Or what should I do to solve this? Sohil R.

UI Testing Failure - Neither element nor any descendant has keyboard focus on TextView

倖福魔咒の 提交于 2019-11-29 07:33:57
I'm facing a problem with 'Textview' type field. I am unable to enter text in FeedbackTextView field. let FeedbackTextView = app.staticTexts["Feedback Textview"] FeedbackTextView.tap() FeedbackTextView.typeText("This is test feedback") Following error is displayed when above code is executed. UI Testing Failure - Neither element nor any descendant has keyboard focus. Element: I faced this same problem with Xcode 7.0.1 and was able to resolve it by turning off the connected hardware keyboard in the simulator settings. Hardware -> Keyboard -> Connect Hardware Keyboard (uncheck this). The

Xcode 7.0 XCTest dyld: could not load inserted library IDEBundleInjection

亡梦爱人 提交于 2019-11-29 05:31:59
I'm running unit tests on my iOS project and when it's running, it crashes and spits this out: dyld: could not load inserted library '/private/var/mobile/Containers/Data/Application/1CAB64C8-D730-427B-8E9E-BD5E152ACFD6/tmp/IDEBundleInjection.framework/IDEBundleInjection' because no suitable image found. Did find: /private/var/mobile/Containers/Data/Application/1CAB64C8-D730-427B-8E9E-BD5E152ACFD6/tmp/IDEBundleInjection.framework/IDEBundleInjection: mmap() error 1 at address=0x00436000, size=0x00004000 segment=__TEXT in Segment::map() mapping /private/var/mobile/Containers/Data/Application

Use of undeclared type 'ViewController' when unit testing my own ViewController in Swift?

冷暖自知 提交于 2019-11-29 05:31:11
问题 I have been trying to write test cases in Swift to test my ViewController. However, when I try to instantiate my own ViewController in a XCTestCase I get "Use of undeclared type 'ViewController' " . (ViewController is the name of my own UIViewController class) Has anyone else faced this issue before? I am using Xcode 6 beta 5 回答1: Swift 1 You should add ViewController.swift file's target membership also as your test target also if you are not using framework. Select class file add to target