开发者

Making Non-Interface Methods Testable in Objective-C

I'm currently writing an Objective-C class which has a relatively complex method in its interface. For the purpose of the question, I'll use the following declaration...

@interface Processor : NSObject {

}

- (NSObject*)doSomeComplicatedProcessing:(NSObject*)param;

@end

So doSomeComplicatedProcessing is my complicated method. In my implementation of doSomeComplicatedProcessing I invoke a series of other methods which are declared and implemented in Processor.m (i.e. they are not part of the interface). The metho开发者_开发知识库ds are not part of the interface as they are used solely in the implementation of doSomeComplicatedProcessing and would not be of use to clients of Processor.

I'm wondering what the best practice is for testing these methods? Obviously I can test doSomeComplicatedProcessing as a whole, but what if I want to test the non-interface methods?

I currently invoke these methods and ignore the compiler warning me that Processor 'may not implement method someMethodName', but it leaves me feeling a little dirty. Is there a best practice for Objective-C around this problem?


You could pull the declarations out in a separate header, say Processor+Private.h, which only Processor.m and test code use. Although I wonder whether you can hold up the invariants for these private methods when calling them separately from the outside.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜