1

I have a XC UI test framework written in Xcode with Swift. I run my project through this command

/usr/bin/xcodebuild test-without-building -xctestrun  /Users/hello/Desktop/test/*.xctestrun -destination "id=459dasdsfdsff39693sfdsff7fe097208d" "-only-testing:Test/Class"

Now I have to pass environment variables to my code. Generally for testing, I added variables under Product>Scheme>Edit Scheme>Environment Variables, and added the following code to read them

let param1 = ProcessInfo.processInfo.environment["Param1"] ?? ""
let param2 = ProcessInfo.processInfo.environment["Param2"] ?? ""

The above works fine if I trigger the test through UI.

Now, I am trying to run the same test through command line. I added the following params like this in command line

/usr/bin/xcodebuild test-without-building -xctestrun  /Users/hello/Desktop/test/*.xctestrun -destination "id=459dasdsfdsff39693sfdsff7fe097208d" "-only-testing:Test/Class" Param1=value1 Param2=value2

They do not get picked up, but in the run I see this

Build settings from command line:
    Param1 = value1
    Param2 = value2

Can somebody help me in what I am doing wrong. I did search on Google, and could not find an explanation or an alternative to do this. Some people have suggested using plistbuddy, I gave it a try, but it did not work.

Prakhar
  • 530
  • 10
  • 24
  • Scheme environment variables only work when run from Xcode. You could try using a User Defined build variable https://stackoverflow.com/a/74254208/4975772 – joshuakcockrell Nov 09 '22 at 04:51

0 Answers0