To be able to build and test your project using the terminal window you will need to have the Command Line Tools package installed on your machine. If the machine you want to build and run Xcode tests does already have Xcode 11 installed, then most likely you do already have the command-line tools installed. If you do not have a command-line tools package installed then you can download it from Apple Downloads Page. When building or running Xcode tests you will use the -destination option to specify which iOS device and iOS version should be used.
To learn about the available destinations, open the terminal window on your Mac machine and use the below command:. The above command will print a list of available destinations you can use to build and run Xcode unit tests. To build Unit Tests from the command line you will need to use the xcodebuild command. Once you are in the root folder of your Xcode project, execute the above command with the details of your project.
Like so:. If you are not sure what Simulator name and OS version are available to use, then run the following command to get a list of destinations: instruments -s devices. To verify that it was installed successfully, you can run the following command in your terminal:.
The essential xcodebuild command to run a test looks like this:. Using xcodebuild we can list the available schemes for a given Xcode project or workspace target by running the command. The destination argument accepts a key-value pair string. The first key is the platform, which indicates the OS and if your target is a physical device or simulator. For iOS, we can specify if the platform is a local Simulator or a physical device. Note: In macOS You can install the Command Line Tools package by running the xcode-select --install command.
It allows you to manage the active developer directory for Xcode and other BSD development tools. See its man page for more information. Xcode includes all of the command-line tools. If it is installed on your system, remove it to uninstall the command-line tools. To find out what version of Xcode is being used by your tools, run the following command in Terminal:.
Listing 2 Printing the version of Xcode currently used by the command-line tools. It operates on one or more targets contained in your project, or a scheme contained in your project or workspace.
See below for various xcodebuild usage. Be sure to navigate to the directory containing your project or workspace in Terminal before running any of the following commands. To list all targets, build configurations, and schemes used in your project, run the following command in Terminal:. Note: xcodebuild supports various build actions such as build , analyze , and archive that can be performed on your target or scheme. However, build is performed by default when no action is specified as shown in Listing 7.
See Xcode Help's Build configuration file reference for more information about xcconfig files. See Xcode Help's Build setting reference for more information about these build settings.
In Xcode, the Configurations section of your project's Info pane provides a pop-up menu, which sets the default configuration to be used by xcodebuild when building a target. Use this pop-up menu to select a default build configuration for xcodebuild as seen in Figure 2.
To build unit tests without running them from the command line, execute the following command in Terminal:. To run unit tests without building them from the command line, execute any of the following command in Terminal:. The test action requires specifying a scheme and a destination. The -workspace option allows you to specify the name of your workspace. Use this option when your scheme is contained in an Xcode workspace. The -project option allows you to specify the name of your Xcode project.
Use this option when your scheme is contained in an Xcode project. It is required when there are multiple Xcode projects in the same directory and optional, otherwise. The -destination option allows you to specify a destination for your unit tests. The -only-testing and -skip-testing options, which are optional, allow you to run only a specific test and to skip a test, respectively. TestTarget , which is required, is the name of the test bundle.
TestClass and TestMethod , which are both optional, respectively represent the name of the class and the name of the method to be tested. Note: See Xcode Scheme and Run your app in Simulator for more information about scheme and destination, respectively. For macOS apps, destinationspecifier supports the platform and arch keys as seen in Table 1. Both keys are required for running your unit tests in macOS. For iOS and tvOS apps, destinationspecifier supports the platform, name, and id keys as seen in Table 2.
The name and id keys are intergeably used with platform, which is a required key as seen in Listing 11 and Listing Listing 11 Tests the iOS scheme on a device identified by a1c30dd0dcec81cd6ba0dc. The version of iOS or tvOS to simulate such as 9. The name and id keys are intergeably used with platform, which is a required key as shown in Listing 15 and Listing The OS key is optional.
The -destination option also allows you to run the same unit test on multiple destinations. This is done by adding it multiple times to your xcodebuild test command as demonstrated in Listing Note: xcodebuild runs your tests sequentially. You must specify a scheme to use it. To use it, execute the following command in Terminal:. See How do I run unit tests from the command line?
0コメント