Beginner lessons on setting up unit testing in Swift.
On Creation
Easiest way is during project creation. When creating a new project simply tick the checkbox Include Tests.
![](https://i0.wp.com/www.lopau.com/wp-content/uploads/2021/08/Screen-Shot-2021-08-21-at-5.42.30-PM.png?resize=747%2C532&ssl=1)
This should create the basic bundle code and targets.
There are two types unit testing. UI Unit Testing and Unit Testing
![](https://i0.wp.com/www.lopau.com/wp-content/uploads/2021/08/Screen-Shot-2021-08-21-at-5.55.01-PM.png?resize=734%2C446&ssl=1)
Existing Project
If you have an existing project and you want to start adding Unit test. Do the following.
Go to File > New > Target and select Unit Testing Bundle and hit Next then Finish.
![](https://i0.wp.com/www.lopau.com/wp-content/uploads/2021/08/Screen-Shot-2021-08-21-at-5.50.47-PM.png?resize=753%2C556&ssl=1)
Repeat same steps this time select UI Unit Testing Bundle.
Note: Rookie mistake for me was I directly created a new file Unit Testing file which created a file but throws an error as the target was missing.
No such module 'XCTest'