Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing arguments to iOS tests with xcodebuild

Tags:

xcodebuild

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:

Arguments

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.

like image 621
lzm Avatar asked Nov 21 '16 14:11

lzm


2 Answers

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)

like image 80
Grigory Entin Avatar answered Sep 24 '22 19:09

Grigory Entin


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)
    }
}
like image 27
ilonska Avatar answered Sep 22 '22 19:09

ilonska