Mock UIApplication for unit tests in Swift

swiftyjimmy.com

This time I wanted to talk about how to mock UIApplication, or any other library for unit testing. When you are writing unit tests you want to be in control. With a specific input the output must always be what you expect. That is the main reason why you shouldn’t do network requests in unit tests. You don’t want your tests to fail for poor network connection. That’s also why you have to do some extra work with system or 3rd party libraries. But how can you trust an output of a function that uses a system library? You cannot inject the dependency for the class since the source is out of your control. How can you work around this problem? How to make the module testable so that you control the outputs?

Read more...
Linkedin

Want to receive more content like this in your inbox?