Testing
Getting started with testing your Combine code
Published on: May 11, 2020A question that often comes up when folks get into learning Combine is "how do I test code that uses Combine?". In this week's post, I will briefly explain the basics of testing Combine code. I will assume that you already know the basics of testing and Combine. If you're just getting started with both topics or would like a refresher I can recommend that you take a look at the following resources: My series of posts on testing My series of posts on Combine My Practical Combine book if you want to learn a lot more about Combine, and...
Read more...Faking network responses in tests
Published on: October 21, 2019Modern applications often rely on data from a network connection to work as intended. Sometimes they rely heavily on the network and are almost worthless without an internet connection while other apps can function mostly fine without a network connection. What these apps have in common is that they contain code that might be challenging to write tests for. Whenever you write unit tests, you should always strive to make your tests as predictable, reproducible and most importantly independent of external factors as possible. This is a huge difference compared to integration testing where you’d test a certain part of...
Read more...Getting started with unit testing your Swift code on iOS – part 2
Published on: October 2, 2019In part 1 of this two-part blog post, you’ve learned how to write synchronous unit tests for a login view model. As a reminder, you saw how to implement tests for the following requirements: When both login fields are empty, pressing the login button should trigger an error that informs the user that both fields are mandatory. When one of the two fields is empty, pressing the login button should trigger an error that informs the user that the empty field is mandatory. When the user’s email address does not contain an @ symbol, pressing the login button should trigger...
Read more...Getting started with unit testing your Swift code on iOS – part 1
Published on: September 30, 2019Recently, I ran a poll on Twitter and discovered that a lot of people are not sure how to get started writing tests, or they struggle to get time approved to write tests for their code. In this blogpost, I will take you through some of the first steps you can take to start writing tests of your own and help you pave the way to a more stable codebase. Why bother with tests at all? You might be wondering why you should bother with code that tests your code. When you put it like that, the idea might indeed...
Read more...Spend less time maintaining your test suite by using the Builder Pattern
Published on: September 16, 2019Often when we write code, we have to initialize objects. Sometimes the object’s initializer doesn’t take any arguments and a simple let object = MyObject() call suffices to create your object, other times things aren’t so simple and you need to supply multiple arguments to an object’s initializer. If you have read my previous post, Cleaning up your dependencies with protocols , you might have refactored your code to use protocol composition to wrap dependencies up into a single object that only exposes what’s needed to the caller. In this blogpost I would like to show you a technique I...
Read more...