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.
It's about passing environment variables rather of command line arguments, but it looks like there's a chance it's supported in xcodebuild in Xcode 13. From release notes:
xcodebuild now supports passing certain environment variables to test runner processes. In the environment where xcodebuild is invoked, prefix any variable with TEST_RUNNER_ to pass that variable (with the prefix stripped) to XCTest test runner processes. For example, running env TEST_RUNNER_Foo=Bar xcodebuild test ... causes the environment variable Foo=Bar to be set in the test runner’s environment. (74104870)
You can also try creating a preprocessor macros in the build settings. And then pass a value like this (let's assume it's named DARK_MODE):
xcodebuild -project \
-scheme \
-testPlan \
-destination \
-derivedDataPath \
DARK_MODE=NO \
test
And here's how it can be utilized in tests:
override func setUp() {
super.setUp()
if ProcessInfo.processInfo.environment["DARK_MODE"] == "YES" {
SystemSettings.changeUIStyle(to: .dark)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With