Xcode 7 UI Test Order
Asked Answered
A

3

6

I have several UI tests that I can successfully individually or grouped. I ended up breaking my tests up into specific classes and running them that way. The issue I've come across is Xcode executes the UI tests in alphabetical order and not in order it is written/displayed. Any idea on how to get around that?

Thank you

Areta answered 13/11, 2015 at 18:13 Comment(2)
For my tests, I wrote a couple of helper functions. loginIfNeeded() check for a label which is only on the login page then logs in the user. Similar logoutIfNeeded() can be used on any test which need to be started from the login screen.Maddox
@Maddox I am new to write UI Test cases. can you please help me out or give me some example how to write helper functions. thank youVaccinia
D
9

A good test suite shouldn't depend on being executed in a specific order. If yours does, you might have some test pollution. I would add common initialization logic (e.g. logging the user in) to the setUp() method of the relevant tests. Or create a helper method and share that between classes. That, combined with relaunching the app for every test, should make the order of your tests irrelevant.

Doublefaced answered 13/11, 2015 at 18:33 Comment(2)
Thank you for the response. I'm new to all this and have very little experience with code at the moment. I did find your blog and it has helped.Areta
While this is mostly true, I use UI tests for snapshotting the UI and getting visual sign off, so the order of them is still important to me.Montanez
C
6

XC testing is incredibly buggy. Sometimes it seems like the direction of the wind or speed of the Earth's rotation will determine if you get a random failure or not. One fix I found that somewhat alleviates these frustrating issues are if you call this is your tearDown() function:

XCUIApplication().terminate()

Where XCUIApplication() is the application that you're running.

Camden answered 17/11, 2015 at 16:34 Comment(2)
"Incredibly" is an understatementWeatherwise
I laughed at this, but then I cried))) because my tests fail inconsistently, so I can also not properly debug it, as it takes time to even reproduce the fail..... f%#kFrulla
G
0

I know that the answer is a bit outdated. But using TestPlans you gain some control of tests execution order along with tests to be performed during test session.

You just need to open you target's scheme and convert it to use TestPlans enter image description here this window under Choose Product > Scheme > Convert Scheme to use Test Plans

Then you can choose your test plan and select tests to run.

enter image description here

Under Configuratuions tab you can find Execution Order setting enter image description here

I know this is a not 100% what you are looking for. But at least it can give you some hooks how to name some tests to execute in some order. For example first test could be testAuth (to authenticate user) and then other tests named in alphabetic order

Gametocyte answered 6/4, 2023 at 11:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.