Search code examples
facebook-loginocmockkiffacebook

Using OCMock with Facebook


I am new to the concepts of UI Automation Testing so OCMock is decently foreign for me. I was having trouble approaching how I would mock a login. I'm also using the KIF framework which allows me to access things in a view with accessibility labels. However, I don't know how to access the accessibility labels of the view presented when Facebook opens a UIWebView so I'm attempting to mock a FBLoginView class and then mock a login to bypass this problem I'm facing.

Please help by either providing me with knowledge on getting through this with the KIF framework, or knowledge concerning how I would approach using OCMock to mock the FBLoginView class. Thank you


Solution

  • Sorry for making my question so vague but I have answered it myself. I believe the proper way to mock a Facebook login is to mock the FBLoginView Class. Then Mock the Protocol. Call the protocol method "loginViewShowingLoggedInUser:" and pass in the mocked class.

            //mock class       
            id classMock = OCMClassMock([FBLoginView class]);
            //mock delegate
            id protocolMock = OCMProtocolMock(@protocol(FBLoginViewDelegate));
            //mock delegate method
            [protocolMock loginViewShowingLoggedInUser:classMock];
            //verify delegate method called.
            OCMVerify([protocolMock loginViewShowingLoggedInUser:classMock]);