No framework methods in tests

3 views
Skip to first unread message

Eimantas Vaičiūnas

unread,
Sep 26, 2010, 4:00:07 AM9/26/10
to cocoa-...@googlegroups.com
Hi List!

I am trying to do TDD with XCode while building simple framework. I
have successfully setup my framework and test targets. Made test
target dependent on framework so that framework is built before
running the test suite. I have written failing test which expects NO
to be YES. It all works.
When I'm trying to test the actual code from my framework (framework
adds a couple of convenience methods to NSArray class' category) the
build results say that I have sent unrecognized selector to an NSArray
instance. Here is my code for framework and for test:
--- NSArray+Iterators.h
#import <Foundation/NSArray.h>

@interface NSArray (Iterators)

- (NSArray *)each:(void (^)(id obj))block;

@end
---
The implementation file looks like this:
--- NSArray+Iterators.m
#import "NSArray+Iterators.h"

@implementation NSArray (Iterators)

- (NSArray *)each:(void (^)(id obj))block
{
return self;
}

@end
----

Now the test file looks like this:
--- EachTests.m
#import "EachTests.h"
#import "WSEnumerable.h"

@implementation EachTests

- (void)testEachReturnValue
{
NSArray *newArray = [array each:(id)^(NSString *name) {
NSLog(@"%@", name);
}];

STAssertEqualObjects(array, newArray, @"Expected returned array to
be equal to iterated array.");
}

- (void)setUp
{
[self setArray:[NSArray arrayWithObjects:@"Melissa", @"Kasandra",
@"Bermudo", @"Asha", @"Lukoh", nil]];
}
---

The error itself looks like this:
---
otest-i386[3500:903] -[NSCFArray each:]: unrecognized selector sent to
instance 0x1437c0
---

Oddly enough - when I wrote the test, XCode's autocompletion did find
the method in question.

Any help is much appreciated

// E.

Justin Spahr-Summers

unread,
Sep 26, 2010, 5:14:40 AM9/26/10
to cocoa-...@googlegroups.com
2010/9/26 Eimantas Vaičiūnas <enc....@gmail.com>:

It sounds like the category isn't getting linked in to the test rig.
Try adding -all_load to the "Linker Flags" build setting for your unit
test target.

--
Justin Spahr-Summers

Eimantas Vaičiūnas

unread,
Sep 26, 2010, 5:52:01 AM9/26/10
to cocoa-...@googlegroups.com
On Sun, Sep 26, 2010 at 12:14 PM, Justin Spahr-Summers
<justin.sp...@gmail.com> wrote:
> It sounds like the category isn't getting linked in to the test rig.
> Try adding -all_load to the "Linker Flags" build setting for your unit
> test target.
Thanks for your response, Justin.

The category itself isn't loaded indeed. I have tried adding following
method to my category and I get no output whatsoever:
---
+ (void)load
{
NSLog(@"loaded %@", self);
}
---

Adding -all_load did not effect the build. I still get the same error.
My linker flags are these:
-framework Cocoa -framework SenTestingKit -all_load

My target structure is snapshot here:
http://walkingsmarts.com/wp-content/uploads/WSEnumerable.png

Reply all
Reply to author
Forward
0 new messages