xctest

Xcode 5 says tests failed but shows green checkmarks

僤鯓⒐⒋嵵緔 提交于 2019-11-28 22:21:30
I have written a few unit tests in the new XCTest framework of Xcode 5. The tests seem to pass successfully most of the time, but I've come across a strange behaviour where if I run the tests enough times consecutively, eventually I'll get a 'test failed' message and the console will show Program ended with exit code 0 , but there are green checkmarks beside all the tests. What's going wrong here? This is definitely a bug. Submit a report via https://bugreport.apple.com/ feel free to reference my report (15251050). Until the bug is fixed, close the project and re-open it. Build Clean worked

What is the purpose of XCTestCase's setUp method?

故事扮演 提交于 2019-11-28 21:04:30
Per the comment within the default template for XCTestCase regarding setUp : Put setup code here; it will be run once, before the first test case. However, in XCTestCase.h , the comment above setUp states differently: Setup method called before the invocation of each test method in the class. To confirm the actual behavior, I put an NSLog within setUp to count how many times it was called: static int count = 0; - (void)setUp { [super setUp]; count++; NSLog(@"Call Count = %d", count); } This resulted in the setUp method being called before every test method (confirming the comment on XCTestCase

IBDesignable Errors When Adding to Tests Target

痞子三分冷 提交于 2019-11-28 20:26:49
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 to update auto layout status: dlopen(TestTests.xctest, 1): Library not loaded: @rpath/XCTest.framework

How do I unit test HTTP request and response using NSURLSession in iOS 7.1?

£可爱£侵袭症+ 提交于 2019-11-28 17:54:39
I'd like to know how to "unit test" HTTP requests and responses using NSURLSession. Right now, my completion block code does not get called when running as a unit test. However, when the same code is executed from within the AppDelegate (didFinishWithLaunchingOptions), the code inside the completion block is called. As suggested in this thread, NSURLSessionDataTask dataTaskWithURL completion handler not getting called , the use of semaphores and/or dispatch_group is needed "to make sure the main thread is blocked until the network request finishes." My HTTP post code looks like the following.

Is it possible to run XCTest based tests under Instruments in Xcode 5?

烈酒焚心 提交于 2019-11-28 17:33:31
问题 Looking at XCTest and Xcode 5 unit testing and not seeing how to run my unit tests under Instruments in Xcode 5... Specifically I'd like to look for leaks during the test (this doesn't have to be automated in this instance, though clearly that'd be useful). Possible? 回答1: I think this is the easiest way: Set a breakpoint somewhere in your tests (I've been doing it in the setup method) Open a new document in instruments Run the application and make sure it's stopped at a breakpoint From the

NSURL to file path in test bundle with XCTest

只谈情不闲聊 提交于 2019-11-28 17:19:17
问题 I am trying to write an iOS app using TDD and the new XCTest framework. One of my methods retrieves a file from the internet (given a NSURL object) and stores it in the user's documents. The signature of the method is similar to: - (void) fetchAndStoreImage:(NSURL *)imageUrl I'm trying to write the test for this method in a way that it doesn't fail if there is no connection to the internet. My approach (taken from a previous question) is to call the method using a NSURL to an image in the

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

筅森魡賤 提交于 2019-11-28 16:49:29
I'm writing integration tests in Xcode 6 to go alongside my unit and functional tests. XCTest has a setUp() method that gets called before every test. Great! It also has XCTestException's which let me write async tests. Also great! However, I would like to populate my test database with test data before every test and setUp just starts executing tests before the async database call is done. Is there a way to have setUp wait until my database is ready before it runs tests? Here's an example of what I have do now. Since setUp returns before the database is done populating I have to duplicate a

Cannot load underlying module for XCTest

情到浓时终转凉″ 提交于 2019-11-28 16:45:55
I'm working in swift on Xcode and by default it creates a test file that references XCTest. When I set the target membership to my main project it causes this error Cannot load underlying module for XCTest If this target membership is not set the tests runs properly and everything works fine. PS: I'm new to swift and it's probably a dumb question (please enlighten me) The main project does not link with the XCUnit framework. You should create a separate testing target for your project, if one does not already exist, and add your test source files to that target. Select your project in the

iOS UI Testing On an Isolated View

[亡魂溺海] 提交于 2019-11-28 16:23:20
I'm trying to incorporate UI tests in my iOS project, but one thing that continues to hold me up is the fact that it seems all of the tests you write must start from the beginning of the app and work their way through. For example, if I want to test a view that is behind a login screen, my tests must first run on the login screen, enter a username/password, click login, then go to the view I want to test. Ideally, the tests for the login view and the next one would be completely isolated. Is there a way to do this, or am I missing the philosophy behind UI tests completely? Absolutely! What you

Xcode Unit Testing with Cocoapods

别等时光非礼了梦想. 提交于 2019-11-28 16:16:36
I've been banging my head against a wall with this for the last few days but despite multiple Google/SO/Github searches I can't find a resolution to the issues I'm having! All I'm trying to do is create some unit tests for my app which makes use of Firebase pods. I'm using Xcode 7.3.1 & Cocoapods 1.0.1. Update: Issue remains with Xcode 8.0 With this podfile: platform :ios, '9.0' use_frameworks! inhibit_all_warnings! target 'MyApp' do pod 'Firebase' pod 'Firebase/Auth' pod 'Firebase/Database' pod 'Firebase/Storage' target 'MyAppTests' do inherit! :search_paths end end In my XCTest class I get