I need to access an environment variable named ENV that is set in the xcconfig file for my main app target, but from inside my UI test target.
After doing a ton of googling this is what I've tried:
ENV=$(ENV)
in the test plan configurationprint(ProcessInfo.processInfo.environment)
But $(ENV)
is not expanding to the real value.
I also tried adding a custom entry in the Info.plist
for the UITest target
<key>ENV</key>
<string>$(ENV)</string>
And then accessing it via Bundle.main.infoDictionary
but again I just get the string $(ENV)
. Any idea what I am missing, or is this just impossible because of the way UI tests work in Xcode?
What you have to do is to either use the app target's xcconfig as the build config for your test target. Or if you need to have specific test target's build config, you include the app's xcconfig into your test target xcconfig.
Then in your test plan settings you define your test plan environment var as ENV=$(ENV)
Basically: apptarget.xcconfig: ENV=appenv
testtarget.xcconfig: #include apptarget.xcconfig
in testPlan environment you define: ENV=$(ENV)
XCConfig is used during build time. The $(ENV) has to be expanded in build time to the value you want. You will accomplish that by either using the apptarget.xcconfig as the xcconfig of your test arget or including it into your testarget.xcconfig
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.