Przypadki testowe OCUnit nie działają
Jeśli utworzę nowy projekt zawierający testy jednostkowe, wywoływane są przypadki testowe. Ale kiedy dodaję testy do istniejącego projektu, otrzymuję następujące informacje w dzienniku:
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)'
rozpoczęto o 2013-05-21 14:11:09 +0000 Test Suite 'testShowContacts' rozpoczęto o 2013-05-21 14:11:09 +0000 Test Suite 'testShowContacts' zakończono 2013-05-21 14:11:09 +0000. Wykonano 0 testów, przy 0 niepowodzeniach (0 nieoczekiwanych) w 0.000 (0.000) sekund
DodałemSenTestKit
do frameworków, a następnie dodałem pakiet testowy poprzez Add Target. Gdzie się mylę?
Pozwól, że dodam tutaj metodę i jej przypadek testowy:
// metoda do testowania
-(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);
}
}
}
// oto test:
-(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");
}
Odkryłem, że w zależnościach docelowych projekt został odznaczony. Sprawdziłem to i ponownie przetestowałem, po czym otrzymałem następujące błędy:
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)
Wiem, że prawdopodobnie nie będzie to temat, ponieważ oryginalne pytanie było zupełnie inne, ale czy ktoś może mi powiedzieć, dlaczego te błędy nadchodzą? Dodałem niezbędne ramy.