xctest

Cannot access AppDelegate in XCTestCase objects (or anything that references it)

前提是你 提交于 2019-12-31 02:22:12
问题 I am trying to start unit testing on my swift iOS app but have run in to a total road block. I cannot seem to access anything that uses my appDelegate. My appDelegate has a UserController object which stores and manages the logged on user and it's various pieces of data. In order to simplify calling the userController I created a custom subclass of NSObject which all my model classes subclass. In it it has let userController : UserController = (UIApplication.sharedApplication().delegate as!

Adding test target to an existing project is not working

你说的曾经没有我的故事 提交于 2019-12-30 18:25:13
问题 I need to add test cases to an existing project, so I tried adding a new test target via File -> New -> Target -> Cocoa Touch Testing Bundle From the test navigator filter bar. Even after adding, the target is not getting listed in the test filter bar. May be because of this issue, Product -> Test option is diabled in my project. Also I could see some differnce between the build setting in my project and another sample project I started in Xcode 6.1 in which Product -> Test option is enabled

multiple testPerformance with XCTestCase objective-C

僤鯓⒐⒋嵵緔 提交于 2019-12-30 10:07:33
问题 I have 2 performance test methods in test class. If i run them separately they pass. If i run hole class methods they fail with message: **** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'API violation - multiple calls made to -[XCTestExpectation fulfill].'* Is there any way to include couple performance tests in 1 class? here is sample code: - (void)testPerformanceAuthenticateWithLogin { XCTestExpectation *authenticateExpectation = [self

Mocking singleton/sharedInstance in Swift

泄露秘密 提交于 2019-12-30 09:43:29
问题 I have a class that I want to test using XCTest, and this class looks something like this: public class MyClass: NSObject { func method() { // Do something... // ... SingletonClass.sharedInstance.callMethod() } } The class uses a singleton that is implemented as this: public class SingletonClass: NSObject { // Only accessible using singleton static let sharedInstance = SingletonClass() private override init() { super.init() } func callMethod() { // Do something crazy that shouldn't run under

Mocking singleton/sharedInstance in Swift

巧了我就是萌 提交于 2019-12-30 09:43:14
问题 I have a class that I want to test using XCTest, and this class looks something like this: public class MyClass: NSObject { func method() { // Do something... // ... SingletonClass.sharedInstance.callMethod() } } The class uses a singleton that is implemented as this: public class SingletonClass: NSObject { // Only accessible using singleton static let sharedInstance = SingletonClass() private override init() { super.init() } func callMethod() { // Do something crazy that shouldn't run under

Can I run an XCTest suite multiple times?

巧了我就是萌 提交于 2019-12-30 09:06:09
问题 Is it possible to have Xcode run your unit tests multiple times? I had an issue in several unit tests that caused intermittent failures. Now that I think I've fixed it, my only option appears to mash ⌘ + U until I'm 95% confident the bug is gone. I know other unit testing frameworks make it quite easy to run a single test, test case, or test suite multiple times. Do we have this luxury in XCTest yet? 回答1: It might help you to use func testMultiple() { self.measureBlock() { ... XCTAssert

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

家住魔仙堡 提交于 2019-12-30 03:45:24
问题 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

How to test that staticTexts contains a string using XCTest

帅比萌擦擦* 提交于 2019-12-30 03:02:10
问题 In Xcode UI testing, how do I test that staticTexts contains a string? In the debugger, I can run something like this to print out all the content of staticTexts: po app.staticTexts . But how do I test if a string exists anywhere within all of that content? I can check for the existence of each staticText doing something like app.staticTexts["the content of the staticText"].exists ? but I have to use the exact content of that staticText. How can I use only a string which may be only a part of

IBDesignable Errors When Adding to Tests Target

眉间皱痕 提交于 2019-12-29 03:55:29
问题 I have a simple UIButton subclass that implements IBDesignable with an IBInspectable var: @IBDesignable class Button: UIButton { @IBInspectable var borderColor: UIColor = UIColor.whiteColor() { didSet { layer.borderColor = borderColor.CGColor } } } I am not using this within a framework and it is working in Interface Builder as intended, however, once I add this subclass to my Tests target, it stops rendering live and I get the following errors: Main.storyboard: error: IB Designables: Failed

How to get detail unit test case execution log for iOS in Jenkins environment

こ雲淡風輕ζ 提交于 2019-12-25 03:54:17
问题 While running the Xcode unit test cases through command line I am able to see the below log. Command: xcodebuild -project MyStore2.xcodeproj -scheme MyStore2 -configuration Debug -sdk iphonesimulator7.0 clean test Log: Test Case '-[MyStore2Tests testIsTrue]' started. Test Case '-[MyStore2Tests testIsTrue]' passed (0.000 seconds). Test Suite 'MyStore2Tests' finished at 2014-07-14 13:01:58 +0000. Executed 2 tests, with 1 failure (0 unexpected) in 0.000 (0.000) seconds Test Suite 'MyStore2Tests