sentestingkit

How to read in a local JSON file for testing

非 Y 不嫁゛ 提交于 2019-12-03 15:56:29
问题 I'm trying to write unit tests for json validation (since the app heavily relies on json from a rest API). I have a local file that contains simple json: "goodFeaturedJson.txt" The contents: { "test": "TEST" } The test case: - (void)testJsonIsValid { Featured *featured = [Featured new]; NSString* filepath = [[NSBundle mainBundle]pathForResource:@"goodFeaturedJson" ofType:@"text"]; NSData *data = [NSData dataWithContentsOfFile:filepath]; NSString *jsonString = [[NSString alloc]

OCUnit tests to existing iOS project. “ld: file not found”

蓝咒 提交于 2019-12-03 11:19:15
问题 I've been following this blog post: Adding unit tests to existing project. I'm getting this error however: ld: file not found: Build/Products/Debug-iphoneos/MyApp.app/MyApp Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang failed with exit code 1 I have my test target properties, Bundle Loader = $(BUILT_PRODUCTS_DIR)/MyApp.app/MyApp Test Host = $(BUNDLE_LOADER) (which both equate to: build/Debug-iphoneos/MyApp.app/MyApp) My wild guess is that those variables aren't

How to read in a local JSON file for testing

旧巷老猫 提交于 2019-12-03 05:25:45
I'm trying to write unit tests for json validation (since the app heavily relies on json from a rest API). I have a local file that contains simple json: "goodFeaturedJson.txt" The contents: { "test": "TEST" } The test case: - (void)testJsonIsValid { Featured *featured = [Featured new]; NSString* filepath = [[NSBundle mainBundle]pathForResource:@"goodFeaturedJson" ofType:@"text"]; NSData *data = [NSData dataWithContentsOfFile:filepath]; NSString *jsonString = [[NSString alloc] initWithContentsOfFile:filepath encoding:NSUTF8StringEncoding error:nil];//[[NSString alloc] initWithData:data

What are the advantages of XCTest over SenTestingKit?

非 Y 不嫁゛ 提交于 2019-12-02 22:08:50
I want to do unit testing in iOS. By default test classes are created using XCTest framework classes in Xcode 5. I have used SenTestingKit in earlier versions of iOS. What are the differences between these two frameworks? What are the advantages of XCTest framework. I googled for related documentation but I did not find any. Only thing I found is the interface classes to use inside the kit. Can anyone point me to the related resources. Apple's documentation is notably lacking with regards to testing. It's a shame, because spending five minutes with XCTest made me fall for it. So, here are some

XCTest build errors for test target Xcode 5:

夙愿已清 提交于 2019-11-28 07:14:19
I have set up an XCode 5 iOS 7 project for unit tests. Of course, setting up the unit tests are taking me so long that I'm trying to keep the faith that it's worth it. Struggling for hours over this error: ld: building for iOS Simulator, but linking against dylib built for MacOSX file '/Applications/Xcode5-DP5.app/Contents/Developer/Library/Frameworks/XCTest.framework/XCTest' for architecture i386 Any ideas on how to solve? Check your Framework Search Paths in your test target settings. These can be corrupted when adding the XCTest Framework. Adding XCTest to one of my projects prepended a "/"

How do you load a prototype cell from a storyboard?

点点圈 提交于 2019-11-27 23:34:14
Is there a way to load a prototype cell, along with any IBOutlet connections as defined within a storyboard? Update I want to unit test the cell (a UICollectionViewCell for that mater), hence would like to load it outside of a UIViewController context. Effectively, in the same way that you can load a custom view from a nib, specifying its file's owner and have its IBOutlet(s) set. Edit: As far as I know, it's not possible to use prototype UITableViewCells from a Storyboard anywhere other than the ViewController you created it in. I haven't tried this with unit tests yet but you can easily put

dispatch_sync on main queue hangs in unit test

爱⌒轻易说出口 提交于 2019-11-27 17:49:54
I was having some trouble unit testing some grand central dispatch code with the built in Xcode unit testing framework, SenTestingKit. I managed to boil my problem done to this. I have a unit test that builds a block and tries to execute it on the main thread. However, the block is never actually executed, so the test hangs because it's a synchronous dispatch. - (void)testSample { dispatch_sync(dispatch_get_main_queue(), ^(void) { NSLog(@"on main thread!"); }); STFail(@"FAIL!"); } What is it about the testing environment that causes this to hang? BJ Homer dispatch_sync runs a block on a given

Pattern for unit testing async queue that calls main queue on completion

孤人 提交于 2019-11-27 17:43:08
This is related to my previous question , but different enough that I figured I'd throw it into a new one. I have some code that runs async on a custom queue, then executes a completion block on the main thread when complete. I'd like to write unit test around this method. My method on MyObject looks like this. + (void)doSomethingAsyncThenRunCompletionBlockOnMainQueue:(void (^)())completionBlock { dispatch_queue_t customQueue = dispatch_queue_create("com.myObject.myCustomQueue", 0); dispatch_async(customQueue, ^(void) { dispatch_queue_t currentQueue = dispatch_get_current_queue(); dispatch

Pattern for unit testing async queue that calls main queue on completion

心不动则不痛 提交于 2019-11-26 19:09:10
问题 This is related to my previous question, but different enough that I figured I'd throw it into a new one. I have some code that runs async on a custom queue, then executes a completion block on the main thread when complete. I'd like to write unit test around this method. My method on MyObject looks like this. + (void)doSomethingAsyncThenRunCompletionBlockOnMainQueue:(void (^)())completionBlock { dispatch_queue_t customQueue = dispatch_queue_create("com.myObject.myCustomQueue", 0); dispatch

How do you load a prototype cell from a storyboard?

删除回忆录丶 提交于 2019-11-26 16:54:09
问题 Is there a way to load a prototype cell, along with any IBOutlet connections as defined within a storyboard? Update I want to unit test the cell (a UICollectionViewCell for that mater), hence would like to load it outside of a UIViewController context. Effectively, in the same way that you can load a custom view from a nib, specifying its file's owner and have its IBOutlet(s) set. 回答1: Edit: As far as I know, it's not possible to use prototype UITableViewCells from a Storyboard anywhere other