如何在目标c中连接测试应用程序

时间:2013-01-24 08:42:39

标签: ios objective-c

我是目标c的初学者。我创建了单元测试应用程序我怎么称呼测试方法? 贝娄给出了我的示例代码。 我的项目::

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    int a=25;
    int b=25;

    MyUnitTestTests *myValue;
    if ([myValue respondsToSelector:@selector(testExample:testExample:)])
    {
      int c =  [myValue testExample:25 testExample:10];
       NSLog(@"value %i",c);
    }
    [super viewDidLoad];
}

测试方法::

- (int)testExample:(int )a testExample:(int )b
{
    int c= a+b;
    return c;    
}

有任何错误吗? 我花了很多时间做这个简单的测试。但输出是(值0)

2 个答案:

答案 0 :(得分:0)

您的输出不正确

NSLog(@"value %d", c);

因此,如果没有%i%d,那么它应该是正确的。

还有另一个错误:实例myValue未初始化。

MyUnitTestTests *myValue = [[MyUnitTestTests alloc] init];

答案 1 :(得分:0)

而不是输入int c = [myValue testExample:25 testExample:10];

只需输入[self testExample:25 testExample:10];

并在测试方法中打印日志语句。