XCResultKit

repository·main·Indexed 41 days ago

https://github.com/davidahouse/xcresultkit

A Swift library for parsing and interacting with Xcode's .xcresult files. It provides a type-safe Swift interface for data typically accessed via the xcresulttool and xccov command-line utilities, allowing developers to extract invocation records, test summaries, payloads, and code coverage data on macOS.

Tokens
695
Snippets
4
Records
5
Agent score
1%

What's inside XCResultKit

  1. Overview of XCResultKit

    main

    XCResultKit is a Swift package that provides high-level objects mapping to the JSON data produced by Xcode's xcresulttool and xccov command-line utilities. It handles the JSON parsing required to transform raw .xcresult data into usable Swift objects.

    Note: Because the package executes xcresulttool or xccov via shell commands, it is only compatible with macOS.

  2. Extract test invocation and summary data with XCResultFile

    main

    Use XCResultFile to traverse the hierarchy of an .xcresult file to find test execution details:

    1. Get the top-level record: Use getInvocationRecord() to retrieve the ActionsInvocationRecord.
    2. Get test plan summaries: Use the ID found within the invocation record to call getTestPlanRunSummaries(id:).
    3. Get individual test details: Use a specific test ID to call getActionTestSummary(id:) to get detailed information about a single test.
    // 1. Get top level record
    let invocationRecord = resultFile.getInvocationRecord()
    
    // 2. Get test plan run summaries using an ID from the record
    let testPlanRunSummaries = resultFile.getTestPlanRunSummaries(id: "xxx")
    
    // 3. Get details for an individual test
    let testSummary = resultFile.getActionTestSummary(id: "xxx")
  3. Use XCResultFile to parse .xcresult files

    main

    The XCResultFile class is the primary entry point for the package. To begin, initialize an instance with the file URL of the .xcresult bundle you wish to inspect.

    Once initialized, you can use various methods to extract invocation records, test summaries, payloads, and code coverage data.

    let resultFile = XCResultFile(url: urlToXCResult)
  4. Access and export test attachments (payloads)

    main

    Tests in an .xcresult file can include attachments. You can access these using their payload ID via XCResultFile:

    • Get raw data: Use getPayload(id:) to retrieve the payload object.
    • Export to file: Use exportPayload(id:) to save the attachment contents directly to a file on disk.
    let payload = resultFile.getPayload(id: "123")
    let exportedPath = resultFile.exportPayload(id: "123")
  5. Get code coverage using xccov

    main

    You can retrieve code coverage results by calling getCodeCoverage() on an XCResultFile instance. This method simplifies the process of running xccov and parsing its output.

    let codeCoverage = resultFile.getCodeCoverage()