I'm working on building a UI Test suite for my iOS app. I need to test my app's functionality on several different devices, but right now I have to select the simulator I want, run the tests, and then repeat.
Now that Xcode supports multiple simulators running in parallel, is there a way to run the UI tests across several different device simulators at the same time?
Run the following command in the same directory as your project to run your tests in parallel from the command line:
xcodebuild test -scheme "YourSchemeName" -destination 'platform=iOS Simulator,OS=11.2,name=iPhone 8' -destination 'platform=iOS Simulator,OS=11.2,name=iPhone 6s' -configuration "Debug" ENABLE_TESTABILITY=YES SWIFT_VERSION=4.0 ONLY_ACTIVE_ARCH=YES
You can add -destination 'platform=iOS Simulator,OS=11.2,name=iPhone 8' for a different destination for as many different destinations as you would like.
For a list of simulator names and OSs that are available, run the command:
instruments -s devices
Bear in mind that if you are running tests in the simulator, you will not see the simulators on your screen when running tests through the command line.
In Xcode:
Select your target scheme in Xcode, and "Edit Scheme..."
Find the settings for "Test", and press on the "Info" tab
You'll see a list of your Unit and UI tests, press on the associated
"Options..." button
Select "Execute in parallel on Simulator"
Optionally select "Randomize execution order"
Commandline:
Look at this answer here
Related
I have problem with GPS location while running tests on iOS simulator from command line. I have app that requires location to run, so in my test scheme - "MyProjectUITests" I have set Core Location and Test Location to some GPS coordinates. It works perfectly fine when tests are run from Xcode IDE (8.1 - 8B62) but if i run them from command line:
xcodebuild -workspace MyProject.xcworkspace \
-scheme "MyProjectUITests" \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 7,OS=10.1' \
test
then app do not get location. I've noticed that in case of running from Xcode IDE simulator starts with "Debug > Location" set to "None" but when app/tests starts it is automatically switched to "Custom Location" so app could start without problem, but when tests are run from command line it stays set to "None" and all tests fail.
I am assuming that Xcode IDE executes that tests with some additional settings and I just need to add them to my script. So does anyone knows how exactly it runs tests or where/how I could check it?
i am facing a problem. I want to do a ui test for my application.
i have written six test class where my test cases are included.
I can run my test cases using
"command U" or the clicking in the run button.
But i don't want to do like this.
I want to run my test classes using code i mean using
xctest because after complete my execution, i have to do another task.
can anyone please give an example how i can run my test classes using xctest codding from a class file.
i dont want to use shell script or jenkins, i want it by using xctest framework.
Running tests with xcodebuild
The xcodebuild command-line tool drives tests just like the Xcode IDE. Run xcodebuild with the action test and specify different destinations with the -destination argument. For example, to test MyApp on the local OS X “My Mac 64 Bit,” specify that destination and architecture with this command:
> xcodebuild test -project MyAppProject.xcodeproj -scheme MyApp -destination 'platform=OS X,arch=x86_64'
If you have development-enabled devices plugged in, you can call them out by name or id. For example, if you have an iPod touch named “Development iPod touch” connected that you want to test your code on, you use the following command:
> xcodebuild test -project MyAppProject.xcodeproj -scheme MyApp -destination 'platform=iOS,name=Development iPod touch'
Tests can run in Simulator, too. Use the simulator to target different form factors, operating systems, and OS versions easily. Simulator destinations can be specified by name or id. For example:
> xcodebuild test -project MyAppProject.xcodeproj -scheme MyApp -destination 'platform=Simulator,name=iPhone,OS=8.1'
Source
Edit your Xcode scheme.
Click the disclosure triangle next to "Test" to reveal more options.
Select "Post-actions"
Click '+' to add any actions to run after tests are complete.
As you can see, your choices are to run a script, or send a simple email. For more information on configuring actions, see https://michele.io/the-project-file-part-2/
I am using XCode7-UItest for testing my application.
I have added few logs in files for my UITestTarget. These test will be executed on device via my build machine's Xcode. I can view these logs on Xcode under "Show report navigator" option but I want to send these logs from build machine to other developers so that they can view those logs.
Is there a way to collect and export these UITest logs through Xcode ?
Only way I could find to do this by copy pasting the logs from XCode manually, and that is cumbersome process.
There doesn't seem to be a way to export the logs from xcode but as a workaround, In case you are running build/test with xcodebuild you can get the NSLog output in your test results for UI Tests from command line tool,
xcodebuild -workspace my.xcworkspace -scheme myscheme -configuration Debug -sdk iphonesimulator9.0 -destination 'platform=iOS Simulator,name=iPhone 6,OS=9.0' test
You can pass iOS device as destination specifier instead of simulator.
I also looked at xcode test logging for the UI tests, Xcode generates the formatted test results with some pre-defined keys as {UDID}_TestSummaries.plist under Logs/Test directory of app DerivedData.Though it won't show you the NSLog data but every Test result log that appears under Report Navigator is stored as key-val here.You can convert this .plist to Dictionary and load it into your code to export it any format you wish.
Hope this helps.
This blog test-logs is what answers it all.
Is it possible to configure Xcode in such a way so when I run all of my test each one will be performed on a "new iPhone Simulator". I'm testing UI related stuff and I want each test to start on a newly opened application.
Currently, application is starting only once and all of the tests are starting one after another and sometimes the ending state after one test is not good for the next test to start.
Solved
I used XCTool (https://github.com/facebook/xctool)
I was able to run one particulatr test by invoking command:
xctool -workspace WorkspaceName.xcworkspace -scheme Workspace -sdk iphonesimulator run-tests -only TestTarget:TestClass/test_Some_Method
Then I simply wrote a script to run all of the tests I had. This way every test triggers simulator to run application once again from scratch.
You could, before the next test, delete the app as you would do it in a real iPhone.
Hi I'm following examples from Test Driven iOS development and I've written a few unit tests with the new Xcode 5 and XCTest. My tests fail with the Xcode GUI client, but when I use xcodebuild the status code is 0.
xcodebuild -target TemperatureConverterTests build
and
echo $?
returns 0.
The tests are suppose to fail. Is the command to run the test cases correct?
xcodebuild command has changed with xcode 5. Here is a script to run Unit tests :
Don't forget that schemes must be shared, you've got to create your Tests Scheme, Xcode 5 didn't create it for you
xcodebuild -workspace MyApp.xcworkspace -scheme myApp-Tests -destination=build -configuration Debug -sdk iphonesimulator7.0 ONLY_ACTIVE_ARCH=YES clean build test
Hope this helps :)
If you don't want (as you rarely need) a separate (and annoying) "scheme" for your testing "target"... Use a variation on #Rémy Virin's answer...
xcodebuild -scheme YourAppOrLib -target YourAppOrLibTests
As pictured below.. this allows you to run the Unit tests for the target.... without cluttering the project with non-production schemes... In this case IndexedKeyMap is my YourAppOrLib.