0

我是目标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)

4

2 回答 2

0

Instead of typing int c = [myValue testExample:25 testExample:10];

Just type [self testExample:25 testExample:10];

And print the log statement in your test method.

于 2013-01-24T09:33:25.443 回答
0

你的输出不正确

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

因此,没有%i和有%d它应该是正确的。

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

MyUnitTestTests *myValue = [[MyUnitTestTests alloc] init];
于 2013-01-24T08:44:57.480 回答