'Xcodebuild: Unable to find a destination matching the provided destination specifier

I want to test same unit test on various platform versions. However, I can't due to a xcodebuild error.

I built my project

 xcodebuild build-for-testing \
     -configuration Debug \
     -scheme UnitTest \
     -sdk iphonesimulator \
     -enableCodeCoverage YES \
     -derivedDataPath "derivedData"

and test project executed successfully with the following command:

xcodebuild test-without-building \
    -configuration Debug \
    -derivedDataPath "derivedData" \
    -resultBundlePath TestResultsA \
    -project UTSSampleSwift.xcodeproj \
    -scheme UnitTest \
    -sdk iphonesimulator \
    -destination 'platform=iOS Simulator,OS=13.5,name=iPhone SE (2nd generation)' \
    -enableCodeCoverage YES

I want to test on OS=12.2 and I already installed the simulators for 12.2 However, the following command fails

xcodebuild test-without-building \
    -configuration Debug \
    -derivedDataPath "derivedData" \
    -resultBundlePath TestResultsE \
    -project UTSSampleSwift.xcodeproj \
    -scheme UnitTest \
    -sdk iphonesimulator \
    -destination 'platform=iOS Simulator,OS=12.2,name=iPhone 8' \
    -enableCodeCoverage YES

With error message:

Build settings from command line:
    SDKROOT = iphonesimulator13.5

xcodebuild: error: Unable to find a destination matching the provided destination specifier:
                { platform:iOS Simulator, OS:12.2, name:iPhone 8 }

        Available destinations for the "UnitTest" scheme:
                { platform:macOS, arch:x86_64, variant:Mac Catalyst, id:521A4BA2-C8DB-50F6-9112-FA4FB75F8B5D }
                { platform:iOS Simulator, id:FB9D6640-64BC-48D2-869F-2D8AE3D10984, OS:13.5, name:iPad (7th generation) }
                { platform:iOS Simulator, id:2327E5B6-8073-4DA7-BB2C-4D9F29E8A74F, OS:13.5, name:iPad Air (3rd generation) }
                { platform:iOS Simulator, id:176CD5F5-F59D-401F-8D9C-2567C97BF14F, OS:13.5, name:iPad Pro (9.7-inch) }
                { platform:iOS Simulator, id:50CDB544-EB94-494D-BA02-2A387F49C36A, OS:13.5, name:iPad Pro (11-inch) (2nd generation) }
                { platform:iOS Simulator, id:2D39CA24-88E5-4012-A461-63404BBF8DD5, OS:13.5, name:iPad Pro (12.9-inch) (4th generation) }
                { platform:iOS Simulator, id:CEC5D35B-9038-4557-ABD8-414290716B84, OS:13.5, name:iPhone 8 }
                { platform:iOS Simulator, id:A375FB0B-6F1C-4249-95B8-EC71D9FB6144, OS:13.5, name:iPhone 8 Plus }
                { platform:iOS Simulator, id:81EFCF5E-372A-4CB4-94D5-409D23237392, OS:13.5, name:iPhone 11 }
                { platform:iOS Simulator, id:884192AD-0156-4E86-87F7-BFC24D451D33, OS:13.5, name:iPhone 11 Pro }
                { platform:iOS Simulator, id:A2F32AF0-CE1E-47F3-9D5A-D3E906B7977B, OS:13.5, name:iPhone 11 Pro Max }
                { platform:iOS Simulator, id:0EB5214D-201F-405F-BDAF-E77089398CA9, OS:13.5, name:iPhone SE (2nd generation) }

        Ineligible destinations for the "UnitTest" scheme:
                { platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Generic iOS Device }
                { platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Generic iOS Simulator Device }

What should I do?

Additional information

xcodebuild -version

Xcode 11.5
Build version 11E608c

xcodebuild -showsdks

iOS SDKs:
    iOS 13.5                        -sdk iphoneos13.5
iOS Simulator SDKs:
    Simulator - iOS 13.5            -sdk iphonesimulator13.5


Solution 1:[1]

I had a similar issue and the issue was my project deployment target was too high. Double check your deployment target is iOS 12.2 or lower.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ben Stoller