OCUnittesting用例没有运行

如果我创build一个包含unit testing的新项目,testing用例会被调用。 但是当我添加testing到一个现有的项目,我在日志中得到以下内容:

2013-05-21 19:41:08.814 otest[51593:7e03] Unknown Device Type. Using UIUserInterfaceIdiomPhone based on screen size Test Suite '/Users/impadmin/Library/Developer/Xcode/DerivedData/SmartDiary-frrybdtgyyjgewbialqsmxkwvlxs/Build/Products/Debug-iphonesimulator/testSmartDiary.octest(Tests)' 

开始于2013-05-21 14:11:09 +0000testing套件'testShowContacts'开始于2013-05-21 14:11:09 +0000testing套件'testShowContacts'于2013-05-21 14:11:09结束+0000。 执行0次testing,在0.000(0.000)秒内发生0次失败(0次意外)

我已经将SenTestKit添加到框架,然后通过添加目标添加testing捆绑。 我哪里错了?

让我在这里添加方法和testing用例:

//要testing的方法

 -(IBAction)addTask{ if(!([mPriority.text isEqualToString:@"1"] ||[mPriority.text isEqualToString:@"2"] ||[mPriority.text isEqualToString:@"3"] ||[mPriority.text isEqualToString:@"4"] ||[mPriority.text isEqualToString:@"5"])) { NSLog(@"Enter valid Priority value"); } else if ([mTaskName.text isEqualToString:@""]) { NSLog(@"Task name can't be blank"); } else{ sqlite3_stmt *statement; const char *dbPath = [mDatabasePath UTF8String]; //[[appViewController returnObject].mDatabasePath UTF8String]; if (sqlite3_open(dbPath, &mDiary) == SQLITE_OK) { NSLog(@"%@",mPriority.text); NSString *insertSQL2=[NSString stringWithFormat:@"INSERT INTO TODO VALUES(\"%@\",\"%@\",\"%@\",\"%@\",\"%@\")",mStartDate.text,mEndDate.text,mTaskName.text,mTaskDescription.text,mPriority.text]; NSLog(@"%@",insertSQL2); const char *insert_stmt2 = [insertSQL2 UTF8String]; sqlite3_prepare_v2(mDiary, insert_stmt2, -1, &statement, NULL); NSLog(@"%@",mPriority.text); if (sqlite3_step(statement) == SQLITE_DONE ) { mStartDate.text=@""; mEndDate.text=@""; mTaskName.text=@""; mTaskDescription.text=@""; mPriority.text=@""; } else { NSLog(@"failed to add"); } sqlite3_finalize(statement); sqlite3_close(mDiary); } } } 

//这里是testing:

 -(void)testAddTask { AddTaskViewController *obj; obj = [[AddTaskViewController alloc]init]; obj.mTaskName.text = @"t1"; obj.mTaskDescription.text = @"t2"; obj.mStartDate.text = @"56987"; obj.mEndDate.text = @"55425"; obj.mPriority.text = @"3"; [obj addTask]; sqlite3_stmt *statement; const char *dbpath = [obj.mDatabasePath UTF8String]; if (sqlite3_open(dbpath,&mDiaryTest)== SQLITE_OK) { NSString *selectSQL = [NSString stringWithFormat:@"SELECT * FROM TODO WHERE mTaskName = \"%@\"",obj.mTaskName.text]; const char *query_stmt = [selectSQL UTF8String]; if (sqlite3_prepare_v2(mDiaryTest, query_stmt, -1, &statement, NULL) == SQLITE_OK) { if(sqlite3_step(statement) == SQLITE_ROW) { testString = [[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)]; } } } sqlite3_finalize(statement); sqlite3_close(mDiaryTest); NSLog(@"%@",testString); STAssertEquals(testString,@"t2",@"should be equal"); } 

我发现在目标依赖项目中,项目没有被选中。 我检查了一遍,再次testing,于是我得到以下错误:

 Undefined symbols for architecture i386: "_OBJC_CLASS_$_AddTaskViewController", referenced from: objc-class-ref in testAddTask.o "_sqlite3_close", referenced from: -[testAddTask testAddTask] in testAddTask.o "_sqlite3_column_text", referenced from: -[testAddTask testAddTask] in testAddTask.o "_sqlite3_finalize", referenced from: -[testAddTask testAddTask] in testAddTask.o "_sqlite3_open", referenced from: -[testAddTask testAddTask] in testAddTask.o "_sqlite3_prepare_v2", referenced from: -[testAddTask testAddTask] in testAddTask.o "_sqlite3_step", referenced from: -[testAddTask testAddTask] in testAddTask.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) 

我知道这可能是个问题,因为原来的问题是完全不同的,但是谁能告诉我为什么会出现这些错误? 我已经添加了必要的框架。

当你正在testingUIKit相关的东西,你想运行应用程序testing 。 确保已经设置了Bundle LoaderTest Host构build设置(请参阅文档 )。

此外,您还必须将libsqlite3.0.dylib链接到您的testing目标,因为您在unit testing中使用了sqlite函数。