Passing arguments to iOS tests with xcodebuild

时光毁灭记忆、已成空白 提交于 2021-01-20 19:38:23

问题


I'd like to pass command line arguments to my iOS tests through the command line (xcodebuild). I'm looking for the equivalent of this setting on XCode:

Simply passing the argument to xcodebuild doesn't work, e.g.:

xcodebuild -verbose test -workspace theworkspace.xcworkspace -scheme 'thescheme' -destination 'platform=iOS Simulator,name=iPhone 7' --argument=value

This question is similar to xcodebuild pass arguments to application on iOS but the solution to that question is not satisfactory.


回答1:


To add to @ManWithBear's answer, I ended up doing this in a script:

#Remove previous command line arguments
/usr/libexec/PlistBuddy -c "Delete DetoxTestRunner:CommandLineArguments" "$TESTRUN" || true
#Add an empty array
/usr/libexec/PlistBuddy -c "Add DetoxTestRunner:CommandLineArguments array" "$TESTRUN"

#Add script arguments as launch arguments of the test runner app
for i in $*; do
  /usr/libexec/PlistBuddy -c "Add DetoxTestRunner:CommandLineArguments: string '$i'" "$TESTRUN"
done

In the code above, I add all arguments passed to a script as launch argument to the tester app. DetoxTestRunner is the name if the test scheme/target.




回答2:


I didn't manage to find "easy" solution. So instead I split testing in 3 steps:
1. Run xcodebuild build-for-testing. It will generate xctestrun file in derived data, which contains list of launch arguments
2. Add your desire launch arguments here
3. run xcodebuild test-without-building -xctestrun <%path_to_file_here%>

I wrote script for it. It still need some improvements, so in close time I will share its final form.

Edit: Never had time to update script. So here ugly versions, that suit our needs. https://gist.github.com/ManWithBear/57cbabc8dcd0193d156c376d2d23ff02



来源:https://stackoverflow.com/questions/40722756/passing-arguments-to-ios-tests-with-xcodebuild

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!