I’ve shared my first experiences about backend development in Swift in my previous blog post. This is the follow-up post. I’ll talk about Unit Tests in Swift.
- Swift accepts only one executable file for the app. We need to split app and library to make it testable. Because testing requires the separate executable file.
main.swiftfile is the main executable for app.
LinuxMain.swiftfile is the main executable for tests.
- To split them, we’ll create two targets. One target is the library which will consist of all our code. The other one is the app which will be dependent on the library.
- Do not forget to add ~Tests suffix for your test folders and test files.
LinuxMain.swiftfile must be under the
- Create a static variable inside test classes and use it as a parameter while calling