How can I mock in this case?

Discussion of the OCMock framework. If you have patches we would prefer you to send them to the mailing list, but attaching them to a topic is possible, too.

How can I mock in this case?

Postby PerterPon » 19 Sep 2016, 09:44

Hi, I'm new about this, here is my code, how can I mock in this situation, can anyone help me, please

biz code:
Code: Select all

#import "MyTestClass.h"

@implementation MyBizClass

- (void)testMethod {
    MyTestClass *testClass = [[MyTestClass alloc] init];
    NSString *result = [testClass test];
    NSLog( result ); // this biz code will return @"test", I want to mock this method, and return something else.
}

@end


When I write test code, I want to mock the method 'test' of class 'MyTestClass', if I do the following, it not work:

Code: Select all

#import "MyTestClass.h"
#import "MyBizClass.h"

-(vod)testClass {
    id mockClass = OCMClassMock( [ MyTestClass class] );
    OCMStub( [ mockClass test ] ).andReturn( @"here is mock method" );
}

PerterPon
 

Re: How can I mock in this case?

Postby ian » 01 Dec 2016, 08:31

I think you should use

OCMStub( [ mockClass test ] ).andReturn( @"here is mock method" );

instead of

OCMStub( [ mockClass testMethod] ).andReturn( @"here is mock method" );
ian
 


Return to OCMock