I am trying to write a suite of automated integration tests to test my C# client library calls to the Yahoo Fantasy Sports API. Several API calls require OAuth tokens, which is where I am having some difficulty. I can use a web browser to generate an access key and secret and then pass those along in my test code, but the tokens expire after an hour, so I need to manually regenerate these and update my test configuration any time I want to run the tests.
Are there best practices for writing API integration tests when OAuth tokens are required?
normally such api's offer a way to get authentication tokens without the need to use a browser. I am not sure if yahoo sports is one of those though.
Normally you have to create an application to access an OAuth2 system, they then give you a ClientID and ClientSecret, then you hit a token URL and receive the access token which is then valid for an hour.
You might want to consider not having integration tests at all though. If I were you I would simply mock the Api responses and use that in your tests. So, gt a sample of the response for each call and then simply create a fake response which returns that whenever you hit it. you can then still run your tests.
The question you need to answer is this : what exactly am I testing? Are you testing a third party APi or do you want to test your own code.
Also, don't forget each api allows to be hit a certain number of times during a certain time window. One more reason to fake it, I'd say
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With