0

OCMock を静的クラス ライブラリに構成し、このような単純なメソッドを作成しました。

#import "IOSExample.h"
@implementation IOSExample

-(NSString *)MyTest
{
return @"Nuwanga";
}

-(int *)MyAge
{
    int a=5;
    int b=5;
    int product=a*b;
    return product;
}
 @end

OCUnit テストでは、このメソッドを次のように作成しました。

-(void)testMyAge
{
    int a=5;
    int b=5;
    int product=a*b;
    STAssertTrue((product > 0), @"The Product was less than zero");
}

私の問題は、OCMock 単体テストで戻り値の型のテスト メソッドを作成するにはどうすればよいですか ???

ありがとう

4

2 に答える 2

0

たぶん、あなたは次のようなことをしたいでしょう

-(void)testMyAge
{
    IOSExample *exampleUndertest = [[IOSExample alloc] init];


    STAssertTrue(([exampleUndertest MyAge] > 0), @"The Product was less than zero");
}

よろしく、クエンティン

于 2013-02-25T18:15:12.730 に答える
0

TDD の場合、以下のようにコードを変更できます

-(int *)MyAge:(int)inA and:(int)inB
{
    int product=inA*inB;
    return product;
}

そして、あなたのテストケースはこのようになります

-(void)testMyAge
{
    int product=[sut MyAge:5 and:5];
    STAssertTrue((product > 0), @"The Product was less than zero");
}

この場合、あざける必要はないと思います。

于 2013-05-21T08:25:27.930 に答える