3

I need a set of code to run only when testing the app(UITesting) not when running the app. I have been trying to find whether running the app or it's a UITesting?.

This is new on xcode 8 and above.

Can some help me with this please.

Manoj
  • 1,482
  • 2
  • 20
  • 53
  • Make question more clear. – Jamshed Alam Oct 26 '16 at 07:26
  • Possible duplicate of [How to let the app know if its running Unit tests in a pure Swift project?](http://stackoverflow.com/questions/27500940/how-to-let-the-app-know-if-its-running-unit-tests-in-a-pure-swift-project) – Daniel Sumara Oct 26 '16 at 07:28
  • 1
    @DanielSumara thats a different question and that doesn't work on xcode anymore for UITesting – Manoj Oct 26 '16 at 07:30

1 Answers1

3

Now we can simply check this with one line of code for "UITesting".

[[[NSProcessInfo processInfo] arguments] containsObject:@"-ui_testing"]

-ui_testing would appear only when testing the app.

Manoj
  • 1,482
  • 2
  • 20
  • 53