问题
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