Unit Tests, by definition, are developed to test a single unit of code, in isolation.
Unit Tests should never call out to a ‘real’ network, and i’m here to show you how you can easily stub your network responses so you can continue to test your ‘unit of code’ behaviour upon receipt of pre-defined, stubbed responses.
URLSessionConfiguration allows us to define additional
URLProtocol's which in turn, define the behaviour of requests. …
Here we are going to take a look at one approach we can use to give our View Controllers a different ViewModel for UITests. Afterall, We don’t always care to hit a real service for our UI tests, we just care that it displays correctly when it’s provided with state and/or data change.
So let’s jump in; 🏊♂️
Let’s have a View Model for fetching a Todo Item from some web service, yay.
OK, let’s jump straight in. You have a URLSession object, wether its a fully configured one, or the bare-bones, basic, shared singleton, either way you make your request, get your data and then go about your business…. and that’s great, but what if it wasn’t?
At this year’s WWDC we have seen Apple yet again push the boundaries of iOS, macOS, watchOS and tvOS.
I spent some time watching the Platforms State of the Union tech video and have summarised each area within this post. I apologise if I have missed anything, or if I have misinterpreted any aspect.
In iOS we have seen the entire UI practically opened up to developers. With iOS10 we, as developers, are now able to interact with rich customisable notifications, create Message Apps and of course, integrate with Siri.
This is mostly achievable via Extensions, using Extensions…
So, turns out that many iOSDev’s are being fooled by what the following should return…
Objective C, ok we get it, it’s an Object Orientated programming language dating back some time now and many dev’s would instantly assume that ‘==’ would compare the memory address’ of the 2 strings, instantiated separately and well, they are correct.
So wait hold on, (Thanks @nanasarpong)
Senior iOS Engineer — Advanced Github downloader — Serial StackOverflow browser