…Continued case study of how I approach unit testing of a CoreBluetooth layer in an iOS application.

In Part 1 of this case study, I covered the approach of applying architectural design principles to the layer of my code that was interacting directly with the CoreBluetooth layer, in order to make it fully testable. In this part I will continue where I left off and describe how we can properly test the BluetoothManager class using sophisticated mocks and behavioural assertion.
If you have no idea about what sophisticated mocking and behavioural assertion is, do not worry: All of the design principles used in this case study, are described in detail in the “Unit Testing in Swift” series.


A case study of how I approach unit testing of a CoreBluetooth layer in an iOS application.

When it comes to unit testing the part of your code that interacts directly with the Swift libraries, multiple challenges occur: Library objects are usually final with unavailable initializers. Additionally, Swift library delegate functions do not easily allow replacing the objects with mocked versions. These challenges can, however, be overcome by implementing the principles of proper architecture that I have described in the “Unit Testing In Swift” series.
If you are curious about unit testing in Swift and this is the first time you come across my articles, I would suggest that you start with the introduction to the series.


You’ve reached the fifth and final part of the Unit Testing in Swift series! In this article we will talk about behavioural asserting and look into further enhancing the mock classes, that we created in the previous article, to make behavioural assertion easy in your own test suite. If you are new to unit testing and want to learn how to start unit testing with Swift in Xcode, I suggest you take a step back to Part 1: The Fundamentals of the series, before reading further. As basic mocking is required for the kind of behavioural assertion we will be…


Welcome to the fourth part of the Unit Testing in Swift series! In this article we will look into implementing custom mock classes to be in complete control of your code while unit testing. If you are new to unit testing and want to learn how to start unit testing with Swift in Xcode, I suggest you take a step back to Part 1: The Fundamentals of the series, before reading further. And if you are wondering why mocking is even necessary, you should definitely have a look at Part 3: Proper Architecture. This part of the series is for…


Welcome to the third part of the Unit Testing in Swift series, where we will cover how to improve your overall unit test quality with a good architecture throughout your project. If you are new to unit testing and want to learn how to start unit testing with Swift in Xcode, I suggest you take a step back to Part 1: The Fundamentals of the series, before reading further. This part of the series is for you, if you want to learn how to implement certain design patterns that allow you to be in complete control of your unit tests…


In this second part of the Unit Testing in Swift series, we will cover how to properly test asynchronous code using expectations. If you are new to unit testing and want to learn how to start unit testing with Swift in Xcode, I suggest you take a step back to Part 1: The Fundamentals of the series, before reading further. This part of the series is for you, if you want to learn how to properly test the asynchronous code and functionality within your application.

Let’s begin with an example!

Consider the School example from Part 1: The Fundamentals. Only the currently enrolled students of…


In this first part of the Unit Testing in Swift series, we will cover how to add a unit test target to your project and write your first unit test using the XCTest framework provided by Apple. If you, for whatever reason, missed the introduction to this series, you can read it here.
This part of the series is for you if you want to learn how to start unit testing your own Xcode project or simply just get a better understanding of the fundamentals of unit testing with XCTest in Swift.

Adding a unit test target

If you are starting completely from scratch, you…


Test, test, test!

As much as it may sound like a WHO recommendation in the middle of a COVID19 pandemic, it’s not. It’s the general recommendation for any software developer who values great code quality and peace of mind while developing.
In the following series I will cover everything from why you should thoroughly test your Swift code to how to implement advanced mocking of internal classes in Swift.

The series contains the following articles:

With the table of contents…


In a recent project I came across a problem that I am very sure many other developers face: Calculating the total distance between locations stored in a list. Imagine, for instance, that you have a custom route on a map represented by a list of CLLocation objects. How do you calculate the total length of the route from the CLLocation objects alone? The math behind it is simple and there is absolutely no reason to write a story about that: The total distance equals the sum of distances between all connected pairs of locations in the list. For a list…


Following last year’s release of the Codable protocol, many iOS-developers have been busy removing heavy, custom JSON parsers and replacing them with a smooth and lightweight conformation to Decodable, in the model layer… And I am no exception: In a recent project for a client, I had the joy of enhancing the model layer of a large application with one of the goals being a complete conformation to Codable.

Challenge 1: Nested heterogeneous collections

The transition to Decodable initially went smooth (“happy days when you get to remove code!”). But the removal of the custom JSON parsers resulted in the removal of vital class-type mapping…

Kewin

Lead iOS Engineer @ Jabra 🇩🇰 Full time 💻📲 — part time 🚴🏽‍⛷🏃🏽‍🏊🏼‍

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store