简体   繁体   English

OCUnit测试用例未运行

[英]OCUnit test cases not running

If I create a new project which includes unit tests, the test cases get called. 如果我创建一个包含单元测试的新项目,则会调用测试用例。 But when I'm adding tests to an existing project I'm getting the following in the 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)' 

started at 2013-05-21 14:11:09 +0000 Test Suite 'testShowContacts' started at 2013-05-21 14:11:09 +0000 Test Suite 'testShowContacts' finished at 2013-05-21 14:11:09 +0000. 开始于2013-05-21 14:11:09 +0000测试套件'testShowContacts'开始于2013-05-21 14:11:09 +0000测试套件'testShowContacts'于2013-05-21 14:11:09 +0000。 Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.000) seconds 已执行0次测试,在0.000(0.000)秒内发生0次失败(0次意外)

I've added the SenTestKit to the frameworks, and then added the testing bundle via Add Target. 我已经将SenTestKit添加到框架中,然后通过“添加目标”添加了测试包。 Where am I going wrong? 我要去哪里错了?

Let me add the method and its test case here: 让我在这里添加方法及其测试用例:

//the method to be tested //要测试的方法

-(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);
        }
    }


}

//here's the 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");

}

I found that in target dependencies the project was unchecked. 我发现在目标依赖项中未选中该项目。 I checked it and tested again, whereupon I'm getting the following errors: 我检查了一下并再次测试,结果出现以下错误:

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)

I know this is probably going off topic, since the original question was entirely different, but can anyone please tell me why these errors are coming? 我知道这可能是个话题,因为原始问题完全不同,但是谁能告诉我为什么会出现这些错误? I've added the necessary frameworks. 我添加了必要的框架。

As you are testing UIKit dependent stuff, you want to run Application Tests . 在测试依赖UIKit东西时,您想运行Application Tests Make sure you have set the Bundle Loader and Test Host build settings (refer to the documentation ). 确保设置了Bundle LoaderTest Host构建设置(请参阅文档 )。

Further you have to link the libsqlite3.0.dylib against your tests target too, because you are using sqlite functions in your unit tests. 另外,您还必须将libsqlite3.0.dylib与测试目标链接,因为在单元测试中使用的是sqlite函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM