How do you execute iOS tests without configuring `xcode-select`?

I'm trying to configure a fully automated CI machine for my iOS builds. Fully automated is critical, no human intervention is an option. Also required is that we must be testing our product on older version of the iOS runtime. Naturally this has presented a number of challenges. The latests of which is this:

Upon executing our tests for the older runtimes the simulator fails to launch.

Since the installation and configuration of Xcode happens automatically xcode-select still points to the command line tools. That's not a problem for the entire rest of our run script because the script uses an export DEVELOPER_DIR declaration to set the development environment. Across multiple versions of Xcode both xcrun and xcodebuild respect the correct paths. It's only when we get to the test command:
Code Block
xcodebuild test -workspace Development.xcworkspace -scheme MyProduct -destination "platform=iOS Simulator,id=$DEVICE_ID"

that a problem begins. The full error follows, but the relevant issue seems to be the line xcrun: error: unable to find utility \"simctl\", not a developer tool or in PATH\n indicating that xcrun cannot find simctl. Upon logging into the CI machine checks of xcrun simctl -h return indications that simctl cannot be found until I set my DEVELOPER_DIR, which is what I would expect. But the same is true for xcodebuild.

So the big question becomes: How and why does xcrun lose its environmental variables when being executed by xcodebuild to launch a process during tests and how do I set it correctly?

Thus far I have attempted to set the DEVELOPER_DIR in the test command as shell variable and modify the PATH to include the DEVELOPER_DIR. Additionally, I began trying to boot the simulator before testing. So far no luck.

Full Error

Code Block
2020-06-30 13:02:14.867 xcodebuild[78984:32139389] [MT] IDETestOperationsObserverDebug: (171C5A6F-2E6C-4918-B159-74A9666522FC) Beginning test session MyProductTests-171C5A6F-2E6C-4918-B159-74A9666522FC at 2020-06-30 13:02:14.868 with Xcode 11C29 on target <DVTiPhoneSimulator: 0x7fe483869030> {
SimDevice: iPhone X (2B8B392C-A580-475B-B78F-066583C537C2, iOS 11.4, Booted)
} (11.4 (15F79))
2020-06-30 13:02:44.581 xcodebuild[78984:32139389] [MT] IDETestOperationsObserverDebug: (171C5A6F-2E6C-4918-B159-74A9666522FC) Finished requesting crash reports. Continuing with testing.
2020-06-30 13:02:44.581 xcodebuild[78984:32139389] [MT] IDETestOperationsObserverDebug: (171C5A6F-2E6C-4918-B159-74A9666522FC) Failed to make test runner session:
Error Domain=com.apple.dt.xctest.error Code=14 "Error retrieving daemon unix domain socket from simulator, failed after 30 attempts.; getenv error: Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"" UserInfo={NSLocalizedDescription=Error retrieving daemon unix domain socket from simulator, failed after 30 attempts.; getenv error: Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory", DetailedDescriptionKey={
DiagnosticLaunchCtlPrintTestManager = "xcrun simctl spawn 2B8B392C-A580-475B-B78F-066583C537C2 launchctl print system/com.apple.testmanagerd:\nxcrun: error: unable to find utility \"simctl\", not a developer tool or in PATH\n";
DiagnosticTestManagerLaunchCtlSimSockEnvVar = "xcrun simctl spawn 2B8B392C-A580-475B-B78F-066583C537C2 launchctl getenv TESTMANAGERD_SIM_SOCK:\nxcrun: error: unable to find utility \"simctl\", not a developer tool or in PATH\n";
DiagnosticTestManagerSimSockEnvVar = "xcrun simctl getenv 2B8B392C-A580-475B-B78F-066583C537C2 TESTMANAGERD_SIM_SOCK:\nxcrun: error: unable to find utility \"simctl\", not a developer tool or in PATH\n";
}}


How do you execute iOS tests without configuring `xcode-select`?
 
 
Q