nacho4d
nacho4d

Reputation: 45118

Test case failing at [[MyObject alloc] init]

I have a subclass of UITextView that conforms to UIKeyInput protocol. So I wrote some logic tests. I have no errors and all other test run well but When myTextView object is supposed to be created:

MyTextView *myTextView = [[MyTextView alloc] initWithFrame:frame];

the test stops, (like a break point) It won't continue

I wonder why is this? Perhaps objects of MyTextView cannot be created in logic tests? Do I need an application test here? If that is the case, what is the rule?

ADDED:

This is one of the tests: (I have a couple more but all them stop at the first line)

    - (void)testHasText{
    MyTextView *myTextView = [[MyTextView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    [myTextView setText:@"some text"];
    STAssertTrue([myTextView hasText], @"hasText failed: It has text!");
    [myTextView setText:@""];
    STAssertFalse([myTextView hasText], @"hasText failed: It it empty!");
    [myTextView release];

}

This is the implementation in MyTextView:

- (BOOL)hasText{
    return [[self text] length]>0?YES:NO;
}

I have commented other methods in MyTextView, only left the three related to UIKeyInput.

Also I have added MyTextView.m to the Compile Source list in LogicTests target. Could this be a configuration issue even though I don't get any Linker Error or warning?

Upvotes: 1

Views: 165

Answers (2)

Claus Broch
Claus Broch

Reputation: 9212

Logic tests that only run in the test bundles are not able to use UI elements. You need to create an application test for this.

I can recommend taking a look at FoneMoneky by Gorilla Logic for performing UI related tests. It will enable you to also test the actual UI in unit tests.

Upvotes: 1

Kris Jenkins
Kris Jenkins

Reputation: 4210

You've got one reference to wmTextView, which doesn't seem to exist. That would be the first thing I'd check.

The second would be this past question: UIKit and unit testing

Upvotes: 0

Related Questions