代码来自 ClassMessage 编写:
-(void)showMessage:(Message*) msg
{
if( msg == nil )
{
return;
}
UIAlertView* alertView;
if(msg.url)
{
alertView = [[UIAlertView alloc] initWithTitle:msg.title
message:msg.message
delegate:self
cancelButtonTitle:msg.buttonLabel1
otherButtonTitles:msg.buttonLabel2
, nil];
}
else
{
alertView = [[UIAlertView alloc] initWithTitle:msg.title
message:msg.message
delegate:self
cancelButtonTitle:msg.buttonLabel1
otherButtonTitles:nil];
}
[alertView performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:NO];
}
为上述方法编写单元测试用例!
-(void)testShowMessageMessageURL{
Message *testMessage = [[Message alloc] init];
testMessage.messageId = 1000 ;
testMessage.message = @"Error message";
testMessage.title = @"Error Title";
testMessage.url = @"http://.……….";
testMessage.buttonLabel1 = @"OK";
testMessage.buttonLabel2 = @"Cancel";
testMessage.buttonLabel2 = nil;
@try {
ClassMessage *testClass = [[ClassMessage alloc]init];
if(testMessage.url != nil){
STAssertNoThrow([testClass showMessage:testMessage],@"Should Pass ");
}
}
@catch (NSException *exception) {
NSLog(@"Exception Name %@, Exception Description %@",[exception name],[exception description]);
STFail(@"Should not caught Exception");
}
}
应用程序停止是
CoreFoundation`__HALT:
0xa40880: int3
0xa40881: nopw %cs:(%eax,%eax)
Thread 1: EXC_BreakPoint(code = EXC_i386_BPT,subcode = 0*0)
单击继续程序执行后
我收到错误消息错误消息是:
[testClass showMessage:testMessage] raised -[_NSCFType pointSize]: unrecognized selector sent to instance should not throws any exception.
在覆盖我的测试用例时,我确实遇到了这个问题。
有人建议我做错了什么来覆盖我的测试用例吗?@提前致谢