0

I configured OCMock to my static class library and I created simple method like this.

#import "IOSExample.h"
@implementation IOSExample

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

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

In OCUnit test I created this method like bellow.

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

My problem is How can I create return type test method in OCMock unit test ???

Thankz

Himesh
  • 458
  • 1
  • 3
  • 15

2 Answers2

0

Maybe you want to do something like

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


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

Regards, Quentin

Quentin
  • 1,741
  • 2
  • 18
  • 29
0

For TDD you can modify your code as below

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

And your test case will become like this

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

I dont see any need for mocking in this case.

Prasad Devadiga
  • 2,573
  • 20
  • 43