Unable to execute tests from command line via xcodebuild

本小妞迷上赌 提交于 2020-01-12 02:48:06

问题


I am trying to build and run test cases using command line for iOS test cases. I have given the following command:

xcodebuild -target AppEngineTests -configuration Debug -sdk iphonesimulator TEST_AFTER_BUILD=YES clean build

It builds the app but the testcases are not run.

could someone please help? Thanks


回答1:


I've found the name property to require more specification.

xcodebuild test -workspace #{WORKSPACE_FILE} -scheme #{TEST_SCHEME} -destination 'platform=iOS Simulator,name=iPhone Retina (4-inch),OS=7.0'

Was what finally worked for me. iPhone was limited and/or unpredictable.

As another poster (can't find the citation) mentioned, the 'platform' loosely corresponds to the divider in the target list, 'name' corresponds to the sub-selection, and the OS parameter corresponds to the right side of the chevron in the same list minus 'iOS '.

The documentation is suggestive and sounds authoritative on first glance without actually being full or correct, unfortunately.

Astonishing what a hassle this was. And how well it worked once the right invocation was achieved.




回答2:


You haven't said what version of Xcode you're using, but since you tagged your question with "xctest" it seems safe to assume you have Xcode 5 or later.

Xcode 5 significantly enhances the support for running tests in xcodebuild, via the test verb. You'll need to specify a scheme and destination instead of a target when using this verb, because it acts just like the Test command in the Xcode IDE.

So for example, assuming you have a shared scheme in your project or workspace named AppEngine that has its Test scheme action properly configured, you would be able to just use

xcodebuild test -scheme AppEngine -destination 'platform=iOS Simulator,name=iPad'

to run all of the unit tests configured for the AppEngine scheme in the iOS Simulator configured as an iPad running the latest iOS. More details on the syntax of the destination specifier are in the xcodebuild man page. (You can even use it to run tests on attached iOS devices!)

The scripts that were previously been used to run unit tests have been adjusted to refer users to the test verb instead because with these improvements it's what everyone should be using.




回答3:


It should be noted that you can use instruments -s devices to get a list of all available devices.

You should also pass the string as -destination 'platform=iOS Simulator,id=ID_OF_THE_SIMULATOR' as for some reason, it doesn't like spaces between the key=value pairs.




回答4:


I had a similar issue with Xcode build. In my case the problem was that I didn't have any tests associated with my scheme.

Please see my SO answer (with diagram) here




回答5:


Landed here looking for a resolution for similar xcodebuild error. As as addendum, you can also pass a single key=val to -destination e.g -destination 'platform=iOS' and xcodebuild will tell you all the alternative available for the scheme.

λ ~/Development/app-ios/ task/JIOS-400-Earl-Grey-Spike* xcodebuild -workspace app.xcworkspace -scheme app -destination 'platform=iOS'  -derivedDataPath "build" build-for-testing

User defaults from command line:
    IDEDerivedDataPathOverride = /Users/schoudhary/Development/app-ios/build

xcodebuild: error: Unable to find a destination matching the provided destination specifier:
        { platform:iOS }

    Missing required device specifier option.
    The device type “Generic iOS Device” requires that either “name” or “id” be specified.
    Please supply either “name” or “id”.

    Available destinations for the "App" scheme:
        { platform:iOS Simulator, id:D248DB01-A852-4360-A9C0-2D71AFE478D7, OS:10.3, name:iPad Air }
        { platform:iOS Simulator, id:CE87AF5A-141C-43DA-AE61-AF53593F37F7, OS:10.3, name:iPad Air 2 }
        { platform:iOS Simulator, id:E93B43E4-D24E-4927-B9EE-0375E15DCBD5, OS:10.3, name:iPad Pro (9.7 inch) }
        { platform:iOS Simulator, id:6D71DB17-0FE2-4D5E-BEE6-CC696445BA11, OS:10.3, name:iPad Pro (12.9 inch) }
        { platform:iOS Simulator, id:F7E37EF4-5E72-438A-A286-216C20158B47, OS:10.3, name:iPhone 5 }
        { platform:iOS Simulator, id:24653844-AE99-4B5B-8332-9FFD2208172F, OS:10.3, name:iPhone 5s }
        { platform:iOS Simulator, id:FD2089A4-BF3F-4F98-8E33-B7EFDCFE5B4D, OS:10.3, name:iPhone 6 }
        { platform:iOS Simulator, id:6EF0DFBD-E99E-4EB3-9C51-6E749F41B6E7, OS:10.3, name:iPhone 6 Plus }
        { platform:iOS Simulator, id:846E631C-6285-4B91-9BA6-1AB6E66C88DB, OS:10.3, name:iPhone 6s }
        { platform:iOS Simulator, id:A6943ADC-F6EF-42F6-9958-D966DFC419FC, OS:10.3, name:iPhone 6s Plus }
        { platform:iOS Simulator, id:B41ABED0-7554-438A-97AC-F34943ED4D79, OS:10.3, name:iPhone 7 }
        { platform:iOS Simulator, id:20F1582C-0D19-4F42-9DAD-43138FB923B9, OS:10.3, name:iPhone 7 Plus }
        { platform:iOS Simulator, id:683BB5CA-E0A8-4CE4-B0DD-AED4C4295B90, OS:10.3, name:iPhone SE }

    Ineligible destinations for the "App" 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 }

just another useful way to get the right destination.



来源:https://stackoverflow.com/questions/20237064/unable-to-execute-tests-from-command-line-via-xcodebuild

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!