Skip to content

Stubbing the protocol return as Nil  #151

@AyeChanPyaeSone

Description

@AyeChanPyaeSone

I've tried to stub the protocol method but it return as nil. Please check the following code.

@protocol Client
- (Account* _Nullable) login:(nullable NSString*)username
                                        password:(nonnull NSData*)login;

And I have a object called ClientImplementation that implements Client protocol.

In my testcase, I mock the class like this in setup().

@property(nonatomic, strong) ClientImplementation<Client> *mockClient;
 self.mockClient =  mockObjectAndProtocol([ClientImplementation class],@protocol(Client));

But when i Stub the method it return as nil.

Account *account = [[Account alloc]init];
    account.name = @"fdsafdsfs";
    [given([self.mockClient login:@""passwrod:anything()]) willReturn:account];

May I know what did i do wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions