Swift Unit Testing ( Quick & Nimble )

Unit Testing helps in providing a instant visual feedback how application behaves. Tests and code work together to achieve even better code. Adopting it as part of development results in delivery of quality product. There’s a saying..

“ Better DX = Better UX ” ( Better Development Experience equates to Better User Experience )

Quick’ is a testing framework for Swift built on top of XCTest. which is very similar to Javascript’s Jasmine as many of you are aware of.

Nimble’ is matching framework provides matchers and assertions. Combination of these two creates wonders for swift developers.

Structure of ‘Quick’

spec() to define complete test case composed of multiple sections.

describe explains the component what is being tested for.

Context illustrates the purpose of test case, current state of object exactly like ‘this’

it tells the expected result , can be filled as many valid expects

beforeEach preparation of data for to perform validation in context blocks which can have it’s own beforeEach’s

Let’s consider Watch Model Data , and apply validations to each of those attributes.

‘Nimble’ provides matchers to perform various test validations using expect keyword. Writing a valid expects helps us to cover most of the scenarios in turn eases effort on functional integration testing.

Adopt a practice of including boundary cases for any test you write. eg : In case of numbers make sure to check it’s not negative, Infinity, Constant ,Close range, based on business specifications etc..

Below are few expects on ‘price’.


Using these techniques will strengthen the application code quality , it’ s worth the effort.

You can download the source code of the project

Happy Coding ..!!!

Senior iOS Engineer @ Intuit | Exploring, Experimenting new ways of building mobile apps.

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