Only running unit tests in Xcode if the build was successful
My workflow in Xcode is typical TDD – write a test, run the tests, write some code, run the tests… I set up a “Run Script” build phase, so that every time I build the tests, they are automatically run. The only problem is that the “Run Script” happens whether the build was successful or not. So, I try to build and fail, and then the same exact tests that I already ran, automatically run again – while I sit there and wait.
The solution turned out to be very simple. “Run Script” build phases in Xcode can have input files and output files. The phase is only run if some input files were more recently modified than some output files. Thus, if we set the input file to be the test executable, and the output files to be all the source files, then the tests will only run if the build is successful. It will look something like this when set up:
Recent Comments