hermancain
hermancain

Reputation: 1622

How do you write tests for a library that connects to an authorized account?

I'm writing a library that utilizes the gmail API. Pretty much every function needs to connect to the gmail API and to work properly at all it needs to authenticate.

For example, this library has the ability to change email labels, so to test it I could make a dummy account, get credentials, and set up "test emails" in an inbox, change their labels, and check to see if they were changed properly, but how would a third party use that gmail account to perform the unit tests? To use it they'd need access to the account, and that would allow them to change email labels (and other things) and invalidate my unit tests.

Another idea I had was to generate a batch of test emails on-the-fly and then when the tests were done, delete all traces of them. That way each third party that runs the tests would just be able to use their own test accounts.

I'm just wondering if there is a more standard way to do this.

Upvotes: 4

Views: 270

Answers (1)

JFPicard
JFPicard

Reputation: 5168

The best practices is to "mock" or fake all the external dependencies. For example, all the calls of the gmail API should be to a faked interface. You only test that the API has been called with the proper arguments... There a lot of librairies to do the mocks....

Upvotes: 4

Related Questions