Casos de teste OCUnit não estão em execução
Se eu criar um novo projeto que inclua testes de unidade, os casos de teste serão chamados. Mas quando estou adicionando testes a um projeto existente, recebo o seguinte no log:
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)'
iniciado em 2013-05-21 14:11:09 +0000 Test Suite 'testShowContacts' iniciado em 2013-05-21 14:11:09 +0000 Test Suite 'testShowContacts' terminou em 2013-05-21 14:11:09 +0000 Executou 0 testes, com 0 falhas (0 inesperado) em 0.000 (0.000) segundos
Eu adicionei oSenTestKit
aos frameworks e, em seguida, adicionou o pacote de testes via Add Target. Onde eu estou errando?
Deixe-me adicionar o método e seu caso de teste aqui:
// o método a ser testado
-(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);
}
}
}
// aqui está o teste:
-(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");
}
Descobri que nas dependências de destino o projeto estava desmarcado. Eu verifiquei e testei novamente, após o que estou recebendo os seguintes erros:
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)
Eu sei que isso provavelmente está saindo do tópico, já que a pergunta original era completamente diferente, mas alguém pode me dizer por que esses erros estão chegando? Eu adicionei os quadros necessários.