我想用 Objective-C 为我的框架编写单元测试,它是用 swift 编写的。有没有办法从 Objective-C 测试访问框架的内部 API?
最佳答案
如果你有一个类 Foo
并且你想使用内部 API,例如方法 - (void) bar;
你可以在你的测试中创建一个扩展头 Foo+ExposePrivate.h
(不需要创建实现 Foo+ExposePrivate.m
) 并将其导入到需要的地方:
#import "Foo.h"
@interface Foo(ExposePrivate)
- (void) bar;
@end
如果您的类 Foo
本身是内部类,请添加复制类声明:
@interface Foo: SomeFooBase<SomeFooProtocol>
@end
@interface Foo(ExposePrivate)
- (void) bar;
@end
关于objective-c - Objective-C 中的@testable 类比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41504339/