ocunit

iOS unit test: How to set/update/examine firstResponder?

无人久伴 提交于 2019-11-30 04:51:34
How do you write first responder unit tests? I'm trying to write a test to confirm that a method advances focus to the next text field. controller is a descendant of UIViewController . But this exploratory test fails: - (void)testFirstResponder { [controller view]; [[controller firstTextField] becomeFirstResponder]; STAssertTrue([[controller firstTextField] isFirstResponder], nil); } The first line causes the view to be loaded so that its outlets are in place. The text fields are non-nil. But the test never passes. I'm guessing that becomeFirstResponder doesn't set the first responder right

Is it possible to unit test a static library project using XCode's SenTestingKit?

雨燕双飞 提交于 2019-11-30 01:29:45
问题 I've created an iOS unit test target for doing logic tests following the steps provided in Apple's documentation. However my build fails and i get the following error: Undefined symbols: "_OBJC_CLASS_$_MyClass", referenced from: objc-class-ref-to-MyClass in LogicTests.o ld: symbol(s) not found collect2: ld returned 1 exit status Ordinarily, if I wanted to use my static library within an application I would include the library.a file, and the headers(including the MyClass.h file...). Is

OCUnit & NSBundle

隐身守侯 提交于 2019-11-30 01:18:09
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])) { NSString *name = [[NSString alloc] initWithFormat:@"image_%i", aIndex]; NSString *path = [[NSBundle

How do I migrate from SenTestingKit/OCUnit to XCTest?

北城余情 提交于 2019-11-29 22:54:27
I am in the process of migrating my project from Xcode 4.6.3 to Xcode 5.0.2. The project's unit tests were developed with SenTestingKit/OCUnit. Now when I am running the tests in Xcode 5, I get an error from the RunUnitTests script telling me that RunUnitTests is obsolete. Possibly related is this note in the Xcode 5 release notes: SenTestingKit and OCUnit are deprecated. Use the migrator to move to XCTest. Unfortunately, I have not been able to find out more about this mysterious "migrator". Possibly my google-fu is lacking [again], so my main question is: How do I migrate unit tests from

iPhone - Retrieving Resources for logical unit tests

会有一股神秘感。 提交于 2019-11-29 22:15:30
I've been following Apple's documentation on writing unit tests for the iPhone, and out of the box, the routine doesn't seem to work. I'm not sure I understand where the unit test is going to get the reference to the application delegate. My Dependencies are like the following: My_Program_target -> UnitTesting_target -> UnitTests_bundle The following code snippet is where the assert fails. I'm very familiar with CPPUNIT, but I'm having trouble understanding how this crosses over. - (void) testAppDelegate { id yourApplicationDelegate = [[UIApplication sharedApplication] delegate];

Unit Testing Example with OCUnit

a 夏天 提交于 2019-11-29 18:49:32
I'm really struggling to understand unit testing. I do understand the importance of TDD, but all the examples of unit testing I read about seem to be extremely simple and trivial. For example, testing to make sure a property is set or if memory is allocated to an array. Why? If I code out ..alloc] init] , do I really need to make sure it works? I'm new to development so I'm sure I'm missing something here, especially with all the craze surrounding TDD. I think my main issue is I can't find any practical examples. Here is a method setReminderId that seems to be a good candidate for testing.

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

无人久伴 提交于 2019-11-29 10:37:09
问题 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? 回答1: I have also had quite a bit of trouble with Xcode 5's tests. It

iOS unit test: How to set/update/examine firstResponder?

久未见 提交于 2019-11-29 02:20:36
问题 How do you write first responder unit tests? I'm trying to write a test to confirm that a method advances focus to the next text field. controller is a descendant of UIViewController . But this exploratory test fails: - (void)testFirstResponder { [controller view]; [[controller firstTextField] becomeFirstResponder]; STAssertTrue([[controller firstTextField] isFirstResponder], nil); } The first line causes the view to be loaded so that its outlets are in place. The text fields are non-nil. But

SenTestKit: cleaning up after ALL tests have run?

折月煮酒 提交于 2019-11-28 21:34:40
I am using SenTest in XCode for my unit tests. I must run a command-line task for my unit tests to test. I can do that in the +initialize method of my test class (subclass of SenTestCase, of course). I would like to terminate the command-line task when the tests are done. Since there's not an opposite of +initialize, I'm stumped. Is there some way to subclass a SenTest class to do this that I'm overlooking? Don't run your command-line tool in +initialize. That's sent by the Objective-C runtime when the class is first sent any message. Instead, run your command-line tool in your test's +setUp

Why doesn't gcov report any lines being covered by my unit tests?

房东的猫 提交于 2019-11-28 21:26:35
I am using Xcode 3.2 on 10.6, with the shipped version of gcov and default GCC compiler (both version 4.2.1). I have created a dependent Cocoa unit test bundle which is injected into my app, and followed Apple's documentation on setting up a gcov-instrumented build configuration - based on the Debug configuration which doesn't have any compiler optimisations enabled. When I build the test bundle with this 'Gcov-instrumented' configuration, the app launches and the tests are injected and run. Also the coverage statistics files are generated at: build/<AppTarget>.build/Gcov-instrumented/