2

For testing purposes, I want to bypass the login screen of my application. I can do that simply by commenting out the code that pushes the view controller when running tests. However, that's not ideal. I came up with a better way of setting a env var in my scheme and then doing:

if ([NSProcessInfo processInfo].environment[@"TEST"]) { // Running EarlGrey test. }

I'd like to know if there's any better way to detect if I am running EarlGrey tests?

khandpur
  • 705
  • 3
  • 12

1 Answers1

2

As from in the faq, you might want to use a build configuration that allows you to add a check like -

#if EARLGREY_ENV
  NSLog(@"This is being run in an EarlGrey test.");
#else
  NSLog(@"Not an EarlGrey test.");
#endif

You can also add a runtime check like NSClassFromString("EarlGreyImpl") != nil to see if you're running in an EarlGrey environment.

gran_profaci
  • 8,087
  • 15
  • 66
  • 99