NSInvocation 类不应该通过单元测试(对于 iPhone)来调用吗?
我的意图是通用调用一个类的方法,由于该方法有两个以上的参数,我不能使用[myTestClass performSelector:withObject:withObject]
相反,我正在尝试使用 NSInvocation 但是一旦我尝试从 NSInvocation 类实例化,我就会收到构建错误:
2009-12-31 11:12:16.380 otest[2562:903] ******* 关于调用 NSInvocation /Developer/Tools/RunPlatformUnitTests.include:第 415 行:2562 总线错误
“${THIN_TEST_RIG}”“$ {OTHER_TEST_FLAGS}" "${TEST_BUNDLE_PATH}" /Developer/Tools/RunPlatformUnitTests.include:451: 错误:测试台 '/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.2.sdk/Developer/usr/bin /otest' 异常退出,代码为 138(它可能已崩溃)。
我正在测试的班级:
@implementation MyExampleClass
-(void)methodWithArgs:(NSString *)aValue
secondParam:(NSString *)aSecond
thirdParam:(NSString *)aThird
{
NSLog(@"methodWithArgs reached");
}
-(void)methodBlank
{
NSLog(@"methodBlank reached");
}
-(void)isTesting
{
NSLog(@"isTesting reached");
}
@end
我的单元测试:
@interface MyClassTests : SenTestCase
{
}
@end
@implementation MyClassTests
- (void)testNSInvocation
{
Class probeClass = NSClassFromString(@"MyExampleClass");
if (probeClass != Nil) {
SEL selector = NSSelectorFromString(@"isTesting");
NSMethodSignature *sig = [probeClass methodSignatureForSelector:selector];
// the following line causes the error
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig];
// this variation also fails
NSMethodSignature *sig2 = [probeClass
methodSignatureForSelector:@selector(methodWithArgs:secondParam:thirdParam:)];
NSInvocation *inv2 = [NSInvocation invocationWithMethodSignature:sig2];
}
}
@end
在运行时调用具有超过 2 个参数的方法的方法是什么?我是否必须更改方法的签名,使其只有 2 个参数?这是单元测试框架的限制吗?