erikdoe / ocmock

Mock objects for Objective-C
http://ocmock.org
Apache License 2.0
2.16k stars 607 forks source link

Unable to access class methods +(void) while I am write down test case for my own framework -(void) instance methods are working fine using OCMock #508

Closed Azharhussain20 closed 3 years ago

Azharhussain20 commented 3 years ago

Objective-C I am New to OCMock with objective-c, Here what I want to do is I want to access class methods which is a public + (void) methods of my framework right now i can get the access of -(void) instance method but some how class methods are not working as expected and it is throwing an error something like this in XCTestCase file unrecognized selector sent to instance

@property (nonatomic) id cleverMock;

- (void)testWithClassMethod{
    CleverPush *const object = [CleverPush new];
    self.cleverMock = OCMPartialMock(object);

    [self.cleverMock setExpectationOrderMatters:YES];
    [[self.cleverMock expect] getChannelIdFromUserDefault];

    [self.cleverMock getChannelIdFromBundle]; // here I am getting an error of **unrecognized selector sent to instance**
    OCMVerify([self.cleverMock getChannelIdFromUserDefault]);
}
+ (NSString*)getChannelIdFromUserDefault{
    return [[NSUserDefaults standardUserDefaults] stringForKey:@"user_name"];
}
+ (NSString*)getChannelIdFromBundle{
    return [self getChannelIdFromUserDefault];
}

I have spent almost two days on this please suggest me if any one had faced the same issue. Thanks in advance.

erikdoe commented 3 years ago

This does not look like a bug in OCMock. Please ask questions related to the use of OCMock on Stack Overflow using the ocmock tag.

Azharhussain20 commented 3 years ago

@erikdoe i have tried my best to find out the solution regarding above issue but still there are same issues with the class methods.