📈 Unit Testing in Swift: The Fundamentals

Kewin
The Startup
Published in
6 min readJul 9, 2020

--

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 will need to add a unit test target to your Xcode project. Don’t worry, this only takes 30 seconds. Click on the Test Navigator tab in the Xcode Navigator (the left-most window). This tab can also be reached by pressing ⌘ + 6. In the bottom left corner you can add the test target by pressing the ‘+’ button. Follow the instructions on the screen and voila: You are now ready to write your first unit test.

Adding a Unit Test Target is simple.

XCTestCase

Now that we are ready to write unit tests you will find that Xcode has added a unit test class for you. This class…

--

--

Kewin
The Startup

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