Travis CI for iOS
Recently, I wanted to implement continuous integration for my app. I assume many people with me stumbled upon the objc.io article on Travis CI. Unfortunately, this article is very outdated, it's from november 2013.
In the meantime, since the article was written, there has been discussion within Facebook's xctool
project if xctool was going to support Xcode 8. However, we already are at Xcode 9. In the meantime, a lot has changed and the article is outdated.
I personally feel that objc.io should test their articles from time to time, or at least mention that the used techniques are not valid or working anymore. As they are not updating their article, I felt I should publish an update.
So, what basically changed is that xctool has some new commands, for example test has been replaced by run-tests
. Also, xctool
does not build your project anymore, we have to fall back to either xcodebuild
, xcbuild
or Buck (a new project by Facebook).
Assuming you know how to link your project to Travis CI with your GitHub-account, I'll just talk about the .travis.yml
file mainly.
I only highlighted some differences of the .travis.yml
file. You still need to add other elements that are still correct in the objc.io article.
As you can see, there are some differences. For example: (1) we can safely set the language to Swift, nowadays, (2) should still work just fine, however I still prefer using xctool
.
(3) Is just plain wrong, this does not work anymore.
(4) This is how you would call xctool
correctly! Build your workspace with xcodebuild
or any other build system you like and may already use. Then use xctool
to run the tests.
In the Gist at line 14, if you would change -scheme TravisExampleTests
to -scheme TravisExample
you get to run UI tests for free as well. This needs additional configuration, as running it this way ends up in an Assertion failure: NSInternalInconsistencyException, "No target application path specified via test configuration"
.
How can we solve that? Unfortunately, xctool
does not run UITests. We would use (again) Buck, or xcodebuild
for this. Keep in mind that running UI tests takes a lot more in configuration (in the scheme, but also in running xcodebuild) as there has to be a simulator that's booted for example.
An example of calling xcodebuild
for UI testing would be:
xcodebuild test -workspace TravisExample.workspace -scheme TravisExampleUITests -destination 'platform=iOS Simulator,name=iPhone 6,OS=11.2
There's a lot of changes since the article at objc.io has been written, as you can see in the gist. xctool
does not build anymore, it still does testing, although you still need xcodebuild
or any tool except xctool
to run UI tests.
Did this article help you set up your Travis CI environment? Then please clap, comment and give me feedback. Thanks!