在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):facebookarchive/xctool开源软件地址(OpenSource Url):https://github.com/facebookarchive/xctool开源编程语言(OpenSource Language):Objective-C 95.0%开源软件介绍(OpenSource Introduction):xctoolxctool is an extension for Apple's xcodebuild which makes it easier to test iOS and Mac products. It's especially helpful for continuous integration. [ Features • Requirements • Usage • Continuous Integration • Reporters • Configuration • Contributing • Known Issues & Tips • License ] Featuresxctool is drop-in replacement for
Note: Support for building projects with xctool is deprecated and will
not be updated to support future versions of Xcode. We suggest moving to
Requirements
Installationxctool can be installed from homebrew via brew install xctool or can be downloaded and run via the xctool.sh command. Usagexctool's commands and options are mostly a superset of xcodebuild's. In most cases, you can just swap xcodebuild with xctool and things will run as expected but with more attractive output. You can always get help and a full list of options with: path/to/xctool.sh -help Testingxctool has a run-tests action which knows how to run the tests in your scheme. You can optionally limit what tests are run or change the SDK they're run against. To run all tests in your scheme, you would use: path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
run-tests To run just the tests in a specific target, use the path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
run-tests -only SomeTestTarget You can go further and just run a specific test class: path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
run-tests -only SomeTestTarget:SomeTestClass Or, even further and run just a single test method: path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
run-tests -only SomeTestTarget:SomeTestClass/testSomeMethod You can also specify prefix matching for classes or test methods: path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
run-tests -only SomeTestTarget:SomeTestClassPrefix*,SomeTestClass/testSomeMethodPrefix* Alternatively, you can omit a specific item by prefix matching for classes or test methods: path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
run-tests -omit SomeTestTarget:SomeTestClass/testSomeMethodPrefix* You can also run tests against a different SDK: path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
run-tests -test-sdk iphonesimulator5.1 Optionally you can specify By default application tests will wait at most 30 seconds for the simulator
to launch. If you need to change this timeout, use the Building TestsBefore running tests you need to build them. You can use xcodebuild, xcbuild or Buck to do that. For example: xcodebuild \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
build-for-testing Xcode 7If you are using Xcode 7 for building you can continue using xctool to build tests using build-tests or just use test actions to run tests. For example: path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
build-tests You can optionally just build a single test target with the path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
build-tests -only SomeTestTarget Parallelizing Test Runsxctool can optionally run unit tests in parallel, making better use of otherwise idle CPU cores. At Facebook, we've seen 2x and 3x gains by parallelizing our test runs. To allow test bundles to run concurrently, use the path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
run-tests -parallelize The above gives you parallelism, but you're bounded by your slowest test bundle. For example, if you had two test bundles ('A' and 'B'), but 'B' took 10 times as long to run because it contained 10 times as many tests, then the above parallelism won't help much. You can get further gains by breaking your test execution into buckets
using the path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
run-tests -parallelize -logicTestBucketSize 20 The above will break your test execution into buckets of 20 test cases each, and those bundles will be run concurrently. If some of your test bundles are much larger than others, this will help even things out and speed up the overall test run. Building (Xcode 7 only)Note: Support for building projects with xctool is deprecated and isn't
supported in Xcode 8 and later. We suggest moving to Building products with xctool is the same as building them with xcodebuild. If you use workspaces and schemes: path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
build If you use projects and schemes: path/to/xctool.sh \
-project YourProject.xcodeproj \
-scheme YourScheme \
build All of the common options like NOTE: xctool doesn't support directly building targets using
Continuous Integrationxctool is an excellent choice for running your tests under a continuous integration server such as Travis CI or Jenkins. To run tests within a continuous integration environment, you must create Shared Schemes for your application target and ensure that all dependencies (such as CocoaPods) are added explicitly to the Scheme. To do so:
You will now have a new file in the xcshareddata/xcschemes directory underneath your Xcode project. This is the shared Scheme that you just configured. Check this file into your repository and xctool will be able to find and execute your tests on the next CI build. Example Travis CI ConfigurationTravis CI is a very popular continuous
integration system offered for free to Open Source projects. It
integrates well with Github, and it now uses xctool as the default
build and test tool for Objective-C projects. Once you have set up your
shared Scheme for use with xctool, you will need to configure a
If you're using workspaces, your language: objective-c
xcode_workspace: path/to/YourApp.xcworkspace
xcode_scheme: YourApp If you're using projects, your language: objective-c
xcode_project: path/to/YourApp.xcodeproj
xcode_scheme: YourApp For more flexibility, you can also control how Travis installs and invokes xctool: language: objective-c
before_install:
- brew update
- brew install xctool
script: xctool -workspace MyApp.xcworkspace -scheme MyApp test You can learn more about the Travis CI environment for iOS and OS X application by referring to the About OS X Travis CI Environment document and find in-depth documentation for configuring your project by consulting the Getting Started page. Reportersxctool has reporters that output build and test results in different
formats. If you do not specify any reporters yourself, xctool uses
the
You can choose your own reporters with the path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
-reporter plain \
build By default, reporters output to standard out, but you can also direct
the output to a file by adding path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
-reporter plain:/path/to/plain-output.txt \
build You can use as many reporters as you like; just use the Included Reporters
Implementing Your Own ReportersYou can also implement your own reporters using whatever language you like. Reporters in xctool are separate executables that read JSON objects from STDIN and write formatted results to STDOUT. You can invoke reporters by passing their full path via the path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
-reporter /path/to/your/reporter \
test For example, here's a simple reporter in Python that outputs a period for every passing test and an exclamation mark for every failing test: #!/usr/bin/python
import fileinput
import json
import sys
for line in fileinput.input():
obj = json.loads(line)
if obj['event'] == 'end-test':
if obj['succeeded']:
sys.stdout.write('.')
else:
sys.stdout.write('!')
sys.stdout.write('\n') If you're writing a reporter in Objective-C, you'll find the
Configuration (.xctool-args)If you routinely need to pass many arguments to xctool on the command-line, you can use an .xctool-args file to speed up your workflow. If xctool finds an .xctool-args file in the current directory, it will automatically pre-populate its arguments from there. The format is just a JSON array of arguments: [
"-workspace", "YourWorkspace.xcworkspace",
"-scheme", "YourScheme",
"-configuration", "Debug",
"-sdk", "iphonesimulator",
"-arch", "i386"
] Any extra arguments you pass on the command-line will take precedence over those in the .xctool-args file. ContributingBug fixes, improvements, and especially new Reporter implementations are welcome. Before submitting a pull request, please be sure to sign the Facebook Contributor License Agreement. We can't accept pull requests unless it's been signed. Workflow
Be sure to use a separate feature branch and pull request for every self-contained feature. If you need to make changes from feedback, make the changes in place rather than layering on commits (use interactive rebase to edit your earlier commits). Then use git push --force origin my-feature to update your pull request. Workflow (for Facebook people, other committers)Mostly the same, but use branches in the main xctool repo if you prefer. It's a nice way to keep things together.
Known Issues & Tips
LicenseCopyright 2014-present Facebook Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at: http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论