0

i am completely new to xcode ui application test. i have the source of the ios app. But i have to test the app using xcode ui test. currently i am adding new test classes to my ui test by creating new file and adding test cases by recording.

I can run my test class individually. But i want to execute all my test classes at a time. How i can do this.

I am completely new in this domain. Any kind of help will be appreciated.

U can also give me a ui test project link or any link which can help me. I have gone through the apple.developers website.

Oletha
  • 7,324
  • 1
  • 26
  • 46
Eric Ipsum
  • 723
  • 3
  • 10
  • 24

3 Answers3

6

Not sure that I understand, but what happens when you press cmd-U?

Make sure that the UI tests are enabled for the scheme.

enter image description here

enter image description here

matsmats
  • 502
  • 3
  • 12
5

To run all of your tests, you can use the following command in Terminal:

$ xcodebuild test

Alternatively, you can use Scan for a simpler interface.

To automate the running of your tests, you can create a shell script to run this command. If you want the shell script to run automatically, use Jenkins or similar continuous integration software to run the shell script at specified intervals.

You can set a job up to run your tests using xcodebuild or scan, and send an email when the job completes, or just when it fails. There's an excellent blog post on how to install Jenkins on OS X here: https://nickcharlton.net/posts/installing-jenkins-osx-yosemite.html and I've written a blog post with notes about some things that might catch you out with the configuration: http://qualitytesting.tumblr.com/post/142473883709/building-with-jenkins-and-xcode. The email feature is available by default so you just need to configure the email addresses you want to receive the notification when you configure your job.

To run all the tests inside Xcode, you can use cmd+U or go to the Test Navigator on the left-hand side and click the play button that appears when you hover over your test suite.

Oletha
  • 7,324
  • 1
  • 26
  • 46
  • is there any way to run using main file like java in swift? – Eric Ipsum Jun 08 '16 at 08:10
  • As far as I'm aware, to run the Java main method, you still need to tell it to run somehow. In Swift, you can invoke a shell command to run your code or press play in Xcode. How do you want to invoke your tests, if one of these methods doesn't cover it? – Oletha Jun 08 '16 at 10:38
  • actually my target is to build a automation framework where i will have to send a mail after complete my test execution. So, i have to run my code through a file which at first trigger my test execution and after complete the execution, it will complete other steps. Can u please give me a link where i can know how to trigger UI test execution from a file and notified when my test exectuion will be finished????? thanks for ur help – Eric Ipsum Jun 09 '16 at 08:04
  • You can do this using Jenkins, linked in my answer above. You can set up a job to run at regular intervals e.g. every 15 minutes, or at 5am Monday - Friday. You'll also be able to trigger a job to run manually by clicking a button. I'll update my answer to include more details. – Oletha Jun 09 '16 at 10:10
  • thanks a lot for your suggestion, but actually i dont want to run my test classes using command u or jenkins. I want it to run it through xctest framework as i have to do some more task after completing my execution. Please help me how i can trigger or run my test class using xctest from a file? – Eric Ipsum Jun 09 '16 at 15:27
  • Using Jenkins will run through XCTest - your tests are dependent on XCTest. You can add post-build actions to the job configuration to do more actions if you need to. However, if you don't want to use Jenkins, follow [my instructions here](http://qualitytesting.tumblr.com/post/141771752059/run-a-subset-of-xctest-tests-with-fastlanescan) for setting up Scan, and then you can run the tests with a very simple Ruby script: `exec('scan')` – Oletha Jun 09 '16 at 15:37
  • Save the like `exec('scan')` to a file called run_tests.rb in the same directory as your fastlane directory, then in Terminal, `cd` to that directory and run `ruby run_tests.rb` - this should run your tests and you can add post-build actions to the Ruby script if you want. – Oletha Jun 09 '16 at 15:39
  • thanks again ...... ok i will try using scan but it will be better if i invoke or run my test using xctest. – Eric Ipsum Jun 09 '16 at 15:46
  • Scan uses xcodebuild under the hood, which is the usual tool for running tests outside of the Xcode IDE. You can use raw xcodebuild if you want, but I think scan is neater and easier to maintain. Good luck! – Oletha Jun 09 '16 at 15:53
  • i want to run the scan command from swift code. if i run the code, it says env: Scan: No such file or directory .... can u please help me regarding this or i will raise a question where u will give the answer. – Eric Ipsum Jun 21 '16 at 08:36
  • Raise a new question showing how you are trying to run it. :) – Oletha Jun 21 '16 at 08:37
  • http://stackoverflow.com/questions/37939663/run-the-terminal-scan-command-from-swift-code – Eric Ipsum Jun 21 '16 at 08:49
  • here is the new question ... please give suggestion – Eric Ipsum Jun 21 '16 at 08:49
0

Fastlane is a great tool, but in case you would like to run all tests without installing Fastlane, here are some ways:

Testing with scheme:

xcodebuild test -scheme YourSchemeName  -destination 'platform=iOS Simulator,OS=15.2,name=iPhone 13'

Testing with scheme and Test Plan:

xcodebuild test -scheme YourSchemeName  -destination 'platform=iOS Simulator,OS=15.2,name=iPhone 13' -testPlan YourPlanName

Easiest Way: Running your tests from xcode directly, in the xcode menu:

Product -> Test (⌘ + U)
MBH
  • 16,271
  • 19
  • 99
  • 149