Running a Unit Test after each build in Xcode

Guides | Tutorial By 4 years ago

Unit Tests are a good way to ensure things don’t break while coding. In Xcode by default they are run manually. Because it’s manual you may forget to run them, or a new person to the project may not know about them. You can set Xcode up to run them automatically every time you build your app, which ensures nothing will go unnoticed.

Here’s how to do that.

First go to your project settings. Go to the Test target’s “build phases” tab and remove the app from the target dependencies list of the test. We want it to be the other way around.


Now in the “build settings” tab (to the left of the “build phases” tab) specify YES for testing after building. If you work on a project with large amounts of tests, it could be time consuming running them every single time you compile. If you think this will affect you then open the row and specify YES only for your release/distribution configuration.


Remove the app from the bundle loader setting (select the row and hit delete on your keyboard)


Finally, through the top menu bar open the scheme editor “Product > Scheme > Edit Schemeā€¦”. Check the run box for your Test target.


That’s all there is. Now when you compile the tests will be run.