Test location is ignored when test are run from command line - ios

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?

Related

Not able to build Xcode project on real device

I am facing a strange issue:
I am trying to build using this xcode command
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination ‘id={deviceID}' test
But every time I run this command I see an unusual prompt that shows up in the next line --
quote]
I am not sure what quote means and what I am expected to enter. I tried entering other device attributes but still it din help me .
Could some one please help me?
As far as I understand your provided information you are trying to start a test on a real device. Tests are executed on simulator only, which is why Xcode tells you it's not able to build your project.
Try something like this instead:
xcodebuild \
-project WebDriverAgent.xcodeproj \
-scheme WebDriverAgentRunner \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 6,OS=8.1' \
test
As you can see this command tries to build your project on an iPhone 6 simulator with iOS 8.1 installed. You can define this to your liking (e.g. OS=13.0 or another iPhone/iPad).
You can give these reads a try, too, for more examples and a better understanding:
https://www.mokacoding.com/blog/running-tests-from-the-terminal/
https://www.appsdeveloperblog.com/run-xcode-unit-tests-from-the-command-line/

Can I run several iOS UI Tests in Parallel?

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

XCodebuild not running tests on Simulator

I am running the following command from command line to build/test my workspace. The idea is to port it eventually to a CI system. But what happens is that one of the runs succeed but all of the following ones fail. They fail in an odd manner in that the build completes as part of the command but then, I see the message which kicks off the simulator and I see the simulator up but the tests are never run on it. The command is either hung on it forever or it fails with no error message. I tried using xcrun simctl erase all before the command to make sure the simulator is clean. I also tried avoiding specifying derivedDatapath and OBJROOT hoping that would make the builds clean but so far, I am stuck here.
xcodebuild test -workspace <workspace-name> -scheme <scheme-name> -configuration Coverage -sdk iphonesimulator -destination platform='iOS Simulator',OS=9.0,name='iPhone 6'
The final error I see is /usr/bin/touch -c /home-folder/Library/Developer/Xcode/DerivedData/.../Build/Products/Coverage-iphonesimulator/Tests.xctest ** TEST FAILED **
The code runs smoothly from within XCode and the tests always pass. I believe this is some issue with the terminal app connecting to the simulator or the simulator being in a weird state after an earlier run but I could not figure out what could be causing the problem. Any suggestions would be great.
XCode Version: 7.0.1
I don't know if that is the issue, but shouldn't test be at the end of the line? Like this:
xcodebuild -workspace <workspace-name> -scheme <scheme-name> -configuration Coverage -sdk iphonesimulator -destination platform='iOS Simulator',OS=9.0,name='iPhone 6' test

Automatically run tests with each build in Xcode 6

When I run
xcodebuild -workspace ~/Documents/JudgecardXSwift/JudgecardXSwift.xcworkspace -scheme JudgecardXSwift -destination 'platform=iOS Simulator,name=iPhone 6' clean test
from command line, I can successfully run all of my tests.
Now I want to add a run script phase to my Xcode project so it will always run my tests each time I run the app. However, when I added the run script phase with the above xcodebuild command, my build always hangs:
and as you can see, it must be hanging on the run script phase I added, because it has just finished the build phase before it titled Run custom shell script 'Copy Pods Resources':
Is my method of adding a run script phase with the xcodebuild command the proper way to automatically run tests with every build? Why does it cause my build process to hang? Is it causing some kind of infinite loop with each xcodebuild command kicking off another through its run script phase?
Bit late here, so thought I would add my personal experience, but xcodebuild will kick off another build for you, importantly xcodebuild via command line as you have may not run your Build Phases as expected. I have only experienced silent failing copy commands, with those I could view the command in log files, but it did not actually copy the file.
So it may hit an infinite loop, more likely though is it's running through that build, hitting xcodebuild command, and then building as normal without some Build Phases executing properly and thus without running your tests.
In Xcode 9 this works. I've added a run script with:
echo "warning: 🚕🚕🚕 Started running myTests 🚕🚕🚕"
xcodebuild -sdk iphonesimulator -workspace myWorkspace.xcworkspace -scheme "myWorkspaceTests" test -destination 'platform=iOS Simulator,name=iPhone X,OS=11.2' CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
And if one of the tests fail, you're gonna get a build error.

Running tests with xcodebuild often results in a "Test process crashed" since Xcode 6

We are running xcodebuild on our CI system (jenkins, setup as a slave on a mac mini). We've been running this for the last year without any trouble. However, since we updated to Xcode 6.1.1, the build has been unstable. About 50% of our builds fail, reporting:
Testing failed:
testXYZ encountered an error (Test process crashed)
The failing test is different every time, so this seems to us like a problem related to the tooling, and not so much our tests.
To be complete, this is the command we use to run our tests:
xcodebuild -verbose -workspace our.xcworkspace \
-scheme OurScheme \
-destination="platform=iOS Simulator,name=iPhone Retina (4-inch),OS=7.1" \
-configuration Debug \
-sdk iphonesimulator ONLY_ACTIVE_ARCH=YES clean build test
Running the process manually on the CI machine seems to be less dodgy. Are there any new requirements since Xcode 6 that we are missing?
=============== EDIT
After some more research we changed the "destination" command line option from:
-destination="platform=iOS Simulator,name=iPhone Retina (4-inch),OS=7.1"
to:
-destination "platform=iOS Simulator,name=iPhone 4s,OS=7.1"
Mark two differences here:
the equal sign that needs to be removed. The destination was basically ignored, and resulted in the simulator being started with a default (iPhone 4s, iOS 7.0.3 in our case).
the name had to be changed to iPhone 4s. Apparently the device names were changed between Xcode 5 and 6. If you want to check what the device names are, have a look under Window > Devices.
While this doesn't solve the actual crashes on 7.0.3, we are now able to run a stable build on 7.1 and above.

Resources