问题描述
我使用xcodebuild运行 xctests
,需要传入一些环境变量
。
在下面的示例中 ACCOUNT_ID
和 HOST_URL
。
I am running my xctests
using xcodebuild and need to pass in some environment variables
.In the example below ACCOUNT_ID
and HOST_URL
.
我尝试将变量作为环境变量传递,并使用 getenv(ACCOUNT_ID)
xcodebuild从测试中访问它们-project CalculatorTestClient.xcodeproj -scheme CalculatorTestClient -destination'%s'ACCOUNT_ID =%s HOST_URL =%s test
I tried passing in the variables as both environment variable and accessing them from the test using getenv ("ACCOUNT_ID")
xcodebuild -project CalculatorTestClient.xcodeproj -scheme CalculatorTestClient -destination '%s' ACCOUNT_ID=%s HOST_URL=%s test"
并传入它们as user defaults
并使用 [[NSUserDefaults standardUserDefaults] valueForKey:@HOST_URL]访问它们;
xcodebuild -project CalculatorTestClient.xcodeproj -scheme CalculatorTestClient -destination'%s'ACCOUNT_ID =%s HOST_URL =%s test
And passing them in as user defaults
and accessing them using [[NSUserDefaults standardUserDefaults] valueForKey:@"HOST_URL"];
xcodebuild -project CalculatorTestClient.xcodeproj -scheme CalculatorTestClient -destination '%s' ACCOUNT_ID=%s HOST_URL=%s test"
这两种方法都不适用于我。
从命令行传递用户定义变量的最简单方法是什么?
Neither approach worked for me.What is easiest way to pass user defined variables from commandline?
推荐答案
类似于@Paul Young我能够通过对Scheme进行一些修改,让它工作。这是我的解决方案:
Similar to @Paul Young I was able to get this to work, with a couple of modifications to the Scheme. Here's my solution:
对于Xcode中的Scheme(Xcode>您的方案>编辑方案>测试>参数选项卡>环境变量):
For the Scheme in Xcode (Xcode > Your Scheme > Edit Scheme > Test > Arguments tab > Environment Variables):
名称价值
ACCOUNT_ID $(ACCOUNT_ID)
HOST_URL $(HOST_URL)
代码(Swift 3):
In Code (Swift 3):
let accountID = ProcessInfo.processInfo.environment["ACCOUNT_ID"]!
let hostURL = ProcessInfo.processInfo.environment["HOST_URL"]!
在命令行上:
$ xcodebuild -project YourProject.xcodeproj \
-scheme "Your Scheme" \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 7,OS=10.2' \
-derivedDataPath './output' \
ACCOUNT_ID='An Account ID' \
HOST_URL='www.hosturl.com' \
test
这篇关于访问从xcodebuild命令行传入的用户定义变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!