1

I am trying to pass an environment variable to my app when testing. I have already setup the environment variable as shown in the screenshot below:

enter image description here

When I run my Test (UITests) I try to access the variable in the actual app WeatherApp using the following code:

print(ProcessInfo.processInfo.environment["TARGET"])

But it always prints out nil. What am I missing?

Here is the code in my actual app:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    print(ProcessInfo.processInfo.environment["TARGET"]) 


    return true
}
pkamb
  • 33,281
  • 23
  • 160
  • 191
john doe
  • 9,220
  • 23
  • 91
  • 167
  • where in the tests have you written print(ProcessInfo.processInfo.environment["TARGET"]) It should be written under YourUITestClass: XCTestCase and with some func testExample() – hariszaman Apr 09 '20 at 19:53
  • I updated the code. I don't want to access TARGET value inside my test, I want to access it inside my actual app. – john doe Apr 09 '20 at 19:57
  • 1
    @pkamb Thank you so much! Yes that helped and solved my issue. – john doe Apr 09 '20 at 20:10

0 Answers0