XCTool
is a command line tool for executing tests, automatically re-running failures and parsing .xcresult
bundle(s). It is currently intended to be integrated with your performance testing CI pipeline.
To invoke XCTool use the following command:
$ ./XCTool -workspace <workspace-path> -project <project-path> -scheme <scheme-name> -destination <destination(platform,name,OS(for simulator)>
Refer project .xcscheme file for an example usage of the command line arguments.
It starts by executing tests using xcodebuild test
command. Test-failures(i.e. flaky environment) are handled by re-running the failing tests. XCTool
extracts performance test-summaries from .xcresult
bundle(s) produced in a test-run. On completion, test summaries are dump(ed) on the console and .xcresult
bundle(s) are inside project-relative ResultBundles
directory.
XCTool
struct takes path toxcresultBundle
as input and executesxcresulttool
to parse performance test-summaries.ArgParser
struct parses command-line arguments passed during launch. It has a static var to providelaunchArgs
.ResultBundle
class takes path toxcodeproj
as input. It provides project-relative bundle-path for a given test-run.Constants
enum contains constants for executable paths, command-line arguments forxcresulttool
,xcodebuild
and maxRetries on failure. Paths may vary dependending on Xcode's install location.ActionsInvocationRecord
struct containsactions
,metadataRef
andmetrics
parsed from the result-bundle. We extracttestsRefIds
from this nested data-model.ActionTestPlanRunSummaries
struct containssummaries
parsed from the result-bundle. We extractsummaryRefIds
correspoding to each test from this nested data-model.ActionTestSummary
struct containsperformanceMetrics
,duration
,identifier
,name
andtestStatus
parsed from the result-bundle.TestSummary
representing a performance test summary, is created fromActionTestSummary
by associating an additionaltargetName
for each test.REPLExecutor
struct takesREPLCommand
as input and executes that command. It's sync-version decodes the result in a given data-model and the async-version streams standardOutput buffer line-by-line.REPLCommand
struct takeslaunchPath
andarguments
as input. It has sync/asyncrun
methods which launch aProcess
with given inputs and attach aPipe
for reading standardOutput.REPLBuffer
struct temporarily holdsData
buffer as it gets streamed from standardOutput. It has mutating methods toappend
data in buffer and getoutstandingText
from buffer.TestFailure
struct takestestSummaries
and project-configuration to retry/re-run failed-tests, due to flaky environment i.e. mostly XCUITests-Runner issues.
- Execute tests
xcodebuild test -workspace <workspace-path> -scheme <scheme-name> -destination <destination(platform, name, OS)> -resultBundlePath <bundle-path>
- Run specific tests without building
xcodebuild test-without-building -workspace <workspace-path> -scheme <scheme-name> -destination <destination(platform, name, OS)> -resultBundlePath <bundle-path> -only-testing:<test-identifier>
- JSON representation of the root object of the result bundle
xcrun xcresulttool get --format json --path <xcresult-bundle-path>
- Nested object in result bundle can be identified by its reference
xcrun xcresulttool get --format json --path <xcresult-bundle-path> --id REF
xcresulttool
provides description of its format usingxcrun xcresulttool formatDescription
$ xcrun xcresulttool version
xcresulttool version 17017, format version 3.26 (current)$ xcodebuild -version
Xcode 12.0
Build version 12A8189n- macOS 10.15 and later.
- Automatically run tests on a connected device:
https://github.com/fastlane/fastlane/blob/master/fastlane_core/lib/fastlane_core/device_manager.rb#L68
http://www.maytro.com/2014/05/11/using-xcodebuild-to-automatically-run-tests-on-connected-device.html - Use
-xctestrun
option inxcodebuild test-without-building
for distributed build and test machines:
https://developer.apple.com/videos/play/wwdc2016/409/
https://stackoverflow.com/a/47019252 - Send performance output to customisable server endpoints.
- Failure reporting by sending filtered logs and crash-reports to customisable server endpoints.
- Pretty logging without using
xcpretty
.
PRs, issues, ideas and suggestions are very welcome!
XCTool welcomes contributions in the form of GitHub issues and pull-requests:
- For PRs, please add the purpose and summary of your changes in the PR description.
- For issues, please add the steps to reproduce and tools/OS version.
- Make sure you test your contributions.
By submitting a pull request, you represent that you have the right to license your contribution to Soaurabh Kakkar and the community, and agree by submitting the patch that your contributions are licensed under the XCTool project license.
XCTool is licensed under the MIT License
https://developer.apple.com/library/archive/technotes/tn2339/_index.html
https://developer.apple.com/videos/play/wwdc2019/413/?time=2932
https://developer.apple.com/documentation/xcode-release-notes/xcode-11-release-notes
https://www.chargepoint.com/engineering/xcparse/
Finding rough edges in performance tests APIs? XCMetrics aims to fix all those!