NSInvocation クラスは、単体テスト (iPhone の場合) を介して呼び出されることを意図していませんか?
私の意図は、クラスのメソッドを一般的に呼び出すことであり、メソッドには2つ以上のパラメーターがあるため、使用できません[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 つしかないように、メソッドのシグネチャを変更する必要がありますか? これは単体テスト フレームワークの制限ですか?