Running UI tests from command line
Recently I ran into an interesting problem of writing UI tests. More interesting thing lied ahead when I had to run these tests on the command line. Here are some of the tips and tricks on how to run your UI tests through command line with variable options.
If the same of your workspace is myWorkspace.xcworkspace
and the scheme name of UI tests is UITests.scheme
, you can run the following command.
xcodebuild -workspace myWorkspace.xcworkspace -scheme "UITests" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=10.2' test
For iOS Simulator you can give either of following parameters values. You can view the full list on command line with following instruments
command.
instruments -s devices
It will list all available devices with supported iOS versions.
If you want to run only specific tests from the given suite, you can mention it too with -only-testing
flag. The only thing you have to mention if series of UITest names separated by spaces, following named parameter key -only-testing
Say, you want to execute only UITestAddition
and UITestSubtraction
tests, you can write like this
xcodebuild -workspace myWorkspace.xcworkspace -scheme "UITests" -only-testing:SampleAppUITests/UITestAddition -only-testing:SampleAppUITests/UITestSubtraction -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=10.2' test
The output from running UI tests might not be the most pleasant thing in the world. You can tidy it a bit with xcpretty
flag at the end of command
xcodebuild -workspace myWorkspace.xcworkspace -scheme "UITests" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=10.2' test | xcpretty
If you want to run UI tests on device as opposed to simulator, you may run
xcodebuild -workspace myWorkspace.xcworkspace -scheme "UITests" -destination 'platform=iOS,name=My iPod touch' test
Going one step forward, if you want to run UI tests on both device and simulator, you can do following:
xcodebuild -workspace myWorkspace.xcworkspace -scheme "UITests" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=10.2' -destination 'platform=iOS,name=My iPod touch' test
This command will run UI tests on specified simulator and device simultaneously.