ocunit

Simplified asserts in OCUnit

徘徊边缘 提交于 2019-12-05 21:24:25
I just started jusing OCUnit and find the asserts a bit cumbersome. In JUnit I can write a test to compare numbers like below. This test will obviously fail, but this shows the nice, simple assert I can write for two numbers and the feedback I get: "expected <2> but was <3>" with very little code. What I tried so far i XCode is: Which works, but is not as elegant as JUnit. Do you know if it exists assertion macros alà JUnit for XCode (OCUnit)? Also, is it possible to get the red/green bar in XCode? The first thing to be aware of is that OCUnit (aka SenTestingKit.framework) are integrated with

cannot stub class method with OCMock 2.1+ in Xcode 5.0

蹲街弑〆低调 提交于 2019-12-05 16:10:16
I know that OCMock version 2.1+ supports stubbing class methods out of the box. But for some reason it's not working with me. To make sure I isolated the problem, I simply cloned the example OCMock project (which is clearly marked as version 2.2.1) and simply added this inside testMasterViewControllerDeletesItemsFromTableView : id detailViewMock = [OCMockObject mockForClass:[DetailViewController class]]; [[[detailViewMock stub] andReturn:@"hello"] helloWorld]; in DetailViewController.h I added: + (NSString *)helloWorld; and DetailViewController.m : + (NSString *)helloWorld { return @"hello

Using OCUnit to test if an UIAlertView is presented

ぐ巨炮叔叔 提交于 2019-12-04 22:42:46
问题 I'm working on an app that will display a UIAlertView upon hitting it's exit button, only if progress in the game has been made. I was wondering how you would use OCUnit to intercept the UIAlertView and interact with it, or even detect if it has been presented. The only thing I can think of is to monkeypatch [UIAlertViewDelegate willPresentAlertView] , but that makes me want to cry. Does anyone know of a better method of doing this? 回答1: Update : See my blog post How to Unit Test Your Alerts

OCUnit tests fail from the command line but work in Xcode when using Keychain Services

拥有回忆 提交于 2019-12-04 20:46:43
问题 I'm using SFHFKeychainUtils to use Keychain Services in my app. I've written some OCUnit tests that verify the funcionality of this code. Everything works fine when I run the unit tests from Xcode on the iOS simulator or my device. However now I'm trying to set up a CI server and the test is failing when it is run via the command line with error code -25291. Looking that up on Apple's documentation tells me: No trust results are available (errSecNotAvailable). I've linked the Security

Unit Testing in With A Static Library

我只是一个虾纸丫 提交于 2019-12-04 11:54:02
问题 I have an XCode workspace with a user interface project (UI) and a core logic project (Core). I want OCUnit unit tests in the UI project, so I have added a new target for testing, as is commonly done. I am able to run tests just fine until I put in import statements for classes in the main UI target which in turn reference the Core project. The error I get is "Lexical or Preprocessor Issue 'xxx.h' file not found". I do not get this message when I build the main UI target directly. It's as if

OCUnit & NSBundle

空扰寡人 提交于 2019-12-03 18:45:30
问题 I created OCUnit test in concordance with "iPhone Development Guide". Here is the class I want to test: // myClass.h #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface myClass : NSObject { UIImage *image; } @property (readonly) UIImage *image; - (id)initWithIndex:(NSUInteger)aIndex; @end // myClass.m #import "myClass.m" @implementation myClass @synthesize image; - (id)init { return [self initWithIndex:0]; } - (id)initWithIndex:(NSUInteger)aIndex { if ((self = [super init]))

EXC_BAD_ACCESS when accessing parameters in andDo of OCMock

血红的双手。 提交于 2019-12-03 16:14:26
问题 I am trying to write an block of code using OCMock's stub andDo method. In this case UIImageView extension class is being tested. I want to check that the extension calls [self setImage:] with parameter that is non-nil (later other image comparison will be used). When using OCMock's andDo method, the test crashes with EXC_BAD_ACCESS after the block completes. id mockView = [OCMockObject mockForClass:[UIImageView class]]; [[[mockView stub] andDo:^(NSInvocation *invocation) { UIImage *img;

Using OCUnit to test if an UIAlertView is presented

╄→尐↘猪︶ㄣ 提交于 2019-12-03 16:01:36
I'm working on an app that will display a UIAlertView upon hitting it's exit button, only if progress in the game has been made. I was wondering how you would use OCUnit to intercept the UIAlertView and interact with it, or even detect if it has been presented. The only thing I can think of is to monkeypatch [UIAlertViewDelegate willPresentAlertView] , but that makes me want to cry. Does anyone know of a better method of doing this? Update : See my blog post How to Unit Test Your Alerts and Action Sheets The problem with my other answer is that the -showAlertWithMessage: method itself is never

How to run OCUnit logic tests automatically before each build (run) of ios app in xcode 4?

痴心易碎 提交于 2019-12-03 13:31:50
问题 It seems, that I have everything setup right. When I run command-u (or pick product - test from menu) test run fine. Best practices should be, that test should run as often as possible, ideally during each build (understand during each run). How to force XCode 4 to do it? I have tried to: setup target dependency (put main app target to be dependent on test target) enable "test after build" in main app target build settings tick also test target in scheme editor for run main app scheme but

OCUnit tests fail from the command line but work in Xcode when using Keychain Services

*爱你&永不变心* 提交于 2019-12-03 13:26:03
I'm using SFHFKeychainUtils to use Keychain Services in my app. I've written some OCUnit tests that verify the funcionality of this code. Everything works fine when I run the unit tests from Xcode on the iOS simulator or my device. However now I'm trying to set up a CI server and the test is failing when it is run via the command line with error code -25291. Looking that up on Apple's documentation tells me: No trust results are available (errSecNotAvailable). I've linked the Security.framework to my unit test project, it seems like from what I have read on the web this is all I should need to