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.
XCToolstruct takes path toxcresultBundleas input and executesxcresulttoolto parse performance test-summaries.ArgParserstruct parses command-line arguments passed during launch. It has a static var to providelaunchArgs.ResultBundleclass takes path toxcodeprojas input. It provides project-relative bundle-path for a given test-run.Constantsenum contains constants for executable paths, command-line arguments forxcresulttool,xcodebuildand maxRetries on failure. Paths may vary dependending on Xcode's install location.ActionsInvocationRecordstruct containsactions,metadataRefandmetricsparsed from the result-bundle. We extracttestsRefIdsfrom this nested data-model.ActionTestPlanRunSummariesstruct containssummariesparsed from the result-bundle. We extractsummaryRefIdscorrespoding to each test from this nested data-model.ActionTestSummarystruct containsperformanceMetrics,duration,identifier,nameandtestStatusparsed from the result-bundle.TestSummaryrepresenting a performance test summary, is created fromActionTestSummaryby associating an additionaltargetNamefor each test.REPLExecutorstruct takesREPLCommandas 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.REPLCommandstruct takeslaunchPathandargumentsas input. It has sync/asyncrunmethods which launch aProcesswith given inputs and attach aPipefor reading standardOutput.REPLBufferstruct temporarily holdsDatabuffer as it gets streamed from standardOutput. It has mutating methods toappenddata in buffer and getoutstandingTextfrom buffer.TestFailurestruct takestestSummariesand 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 xcresulttoolprovides 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
-xctestrunoption inxcodebuild test-without-buildingfor 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!