nsscreencast / comments

Public comments on NSScreencast.com
0 stars 0 forks source link

CoinList: Stubbing Network Requests #174

Open subdigital opened 3 years ago

subdigital commented 3 years ago

Written on 04/13/2018 15:36:25

URL: https://nsscreencast.com/episodes/335-stubbing-network-requests

subdigital commented 3 years ago

originally written by mak4364 on 04/15/2018 15:21:18

Really enjoying this series - it's very timely for me as I'm developing an app which interacts with a RESTful API. One suggestion and two questions:

* You can write a script which fetches a fresh set of JSON data once per day (or whatever), regardless of how often you run the unit tests. Add it as a Run Script to the Build Phases of your test target. (Reference: https://www.swiftbysundell....

* As you mention in the video, APIs can change over time; specifically, new attributes might be added to the object models containing some useful info. How can we check for that? The only way I could come up with was a brute force approach of adding an array of known attributes to the model (repeating a lot of information already contained in the CodingKeys enum), and then comparing this array to the keys of the return JSON, which I serialize as a simple Dictionary. There's got to be a better way.

* What is a good approach for testing API calls which must be "chained," for example, I need to login (which returns an auth cookie), get a list of objects, and then get more details about one of those specific object by ID?

subdigital commented 3 years ago

originally written by subdigital on 04/15/2018 15:49:43

Thanks for the feedback! That tip about refreshing once per day is a good one. Thanks for the link :)

As for the API updating with additional _useful_ stuff, I think this is best served outside the application. Subscribe to the newsletter for the API owner so you know when things are changing, or there's a new feature you want to take advantage of, etc.

Testing chained API calls (like Request Resource -> 401 -> Refresh credentials -> Retry Request) would be a useful thing to cover. I'll add it to my list.