xctest

Xcode 5 throws “Library not loaded” error when adding a test target

与世无争的帅哥 提交于 2019-11-30 10:50:34
I've tried adding a test target on Xcode 5 using the Add Target -> Add Cocoa Touch Unit Testing Bundle. However, when I run the test, I get the following error: 2013-09-24 10:43:14.446 Stack Exchange[48895:c07] Error loading /Users/arielitovsky/Library/Developer/Xcode/DerivedData/MyApp-fjegcztcnwxqdfdimhonqzzqpdwr/Build/Products/Debug-iphonesimulator/Stack Exchange Tests.xctest/Stack Exchange Tests: dlopen(/Users/arielitovsky/Library/Developer/Xcode/DerivedData/MyApp-fjegcztcnwxqdfdimhonqzzqpdwr/Build/Products/Debug-iphonesimulator/Stack Exchange Tests.xctest/Stack Exchange Tests, 262):

Grant access to NAB programatically on iOS 7.0 Simulator

假如想象 提交于 2019-11-30 09:43:33
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. In the spirit of sharing I am going to answer my own question. Among other permissions, Address Book access permission is stored in TCC.db database that is located in

Test bundle could not be loaded because an unanticipated error

大兔子大兔子 提交于 2019-11-30 08:22:04
Recently I have started writing test case for one old static library. I have loaded the library to Xcode 5,Since Static Library is old , I have to manually add TestProject with Test Target. When I am trying "Product-->Test" , It launches emulator and Console shows following error The test bundle at /xxx/xxx/xxx/StaticLibTest.xctest could not be loaded because an unanticipated error occurred: Error Domain=NSCocoaErrorDomain Code=3587 "The bundle “StaticLibTest.xctest” couldn’t be loaded because it is damaged or missing necessary resources." (dlopen_preflight(/xxx/xxxx/xxx/Debug-iphonesimulator

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

与世无争的帅哥 提交于 2019-11-30 08:04:42
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 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 as shown in image: OR If you are ViewController is within a framework : ViewController class is in different

Xcode 7.0 XCTest dyld: could not load inserted library IDEBundleInjection

China☆狼群 提交于 2019-11-30 07:57:50
问题 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

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

半城伤御伤魂 提交于 2019-11-30 07:51:38
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? I have also had quite a bit of trouble with Xcode 5's tests. It still seems quite buggy with some odd behaviour - however I have found the definitive reason your particular

addUIInterruptionMonitor(withDescription:handler:) not working on iOS 10 or 9

删除回忆录丶 提交于 2019-11-30 05:11:45
The following tests works fine on iOS 11. It dismisses the alert asking permissions to use the locations services and then zooms in in the map. On iOS 10 or 9, it does none of this and the test still succeeds func testExample() { let app = XCUIApplication() var handled = false var appeared = false let token = addUIInterruptionMonitor(withDescription: "Location") { (alert) -> Bool in appeared = true let allow = alert.buttons["Allow"] if allow.exists { allow.tap() handled = true return true } return false } // Interruption won't happen without some kind of action. app.tap()

Is it possible to test IBAction?

空扰寡人 提交于 2019-11-30 05:07:38
问题 It is kinda easy to unit test IBOutlets, but how about IBActions? I was trying to find a way how to do it, but without any luck. Is there any way to unit test connection between IBAction in a View Controller and a button in the nib file? 回答1: For full unit testing, each outlet/action needs three tests: Is the outlet hooked up to a view? Is the outlet connected to the action we want? Invoke the action directly, as if it had been triggered by the outlet. I do this all the time to TDD my view

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

a 夏天 提交于 2019-11-30 04:43:54
I have the following problem. I want to execute a piece of code before all test classes are executed. For instance: I don't want my game to use the SoundEngine singleton during executing, but the SilentSoundEngine. I would like to activate the SilentSoundEngine one time not in all tests. All my tests look like this: class TestBasketExcercise : XCTestCase { override func setUp() { SilentSoundEngine.activate () // SoundEngine is a singleton } // The tests } -Edit- Most of the answers are directed at providing custom superclass for the TestCase. I am looking for a more general and cleaner way to

UI Test Case not show code coverage

纵然是瞬间 提交于 2019-11-30 04:31:41
I have some tests written using XCTestCase classes and I want to calculate code coverage. For the regular test it is shown nicely in my bot, but for UI Tests is always 0%. The simplest test: import XCTest class FAQUITests: XCTestCase { let app = XCUIApplication() override func setUp() { super.setUp() app.launch() } func openFaqView() { app.navigationBars["NavigationBar"].buttons["FAQ"].tap() } func testFaq() { openFaqView() app.tables.cells.elementBoundByIndex(0).tap() } } And this surely should show some test coverage but it's not. I set in my bot code coverage enabled: And result: Still 0%.