xcresultparser

repository·main·Indexed 40 days ago

https://github.com/a7ex/xcresultparser

A tool for parsing binary Xcode .xcresult bundles to generate human-readable or machine-readable summaries of test results and code coverage. It supports multiple output formats including JUnit, Cobertura, HTML, Markdown, and SonarQube XML, and provides options for filtering failed tests, excluding paths, and specifying project roots for path resolution.

Tokens
3.3K
Snippets
15
Records
21
Agent score
100%

What's inside xcresultparser

  1. How flaky tests are handled

    main

    A flaky test (failed on first attempt, passed on retry) is detected from per-repetition results.

    • Visual Output (txt, cli, html, md): Displayed with a distinct flaky icon (🟠 in markdown, ⚠︎ otherwise).
    • JUnit Output: The <testcase> retains its <failure> children but gains a flaky="true" attribute and a [FLAKY] prefix in the failure message.
    • Important: Flaky tests still count as failures for roll-ups, counts, and the --failed-tests-only flag.
  2. How expected failures are handled

    main

    The representation of expected failures depends on the output format:

    • txt, cli, html, md: Expected failures are represented as a distinct test state.
    • junit and xml (Sonar generic): Expected failures are emitted as regular passing test cases to maintain schema compatibility.
  3. Ensure valid SonarQube XML output for Xcode 26

    main

    When using xcresultparser to generate SonarQube generic test execution reports from Xcode 26 result bundles, ensure the following requirements are met to maintain a valid contract:

    • File Path Resolution: Every <file path="..."> must identify the actual test source file. Do not use Swift Testing suite display names as identifiers, as this can cause collisions with production source files.
    • Mandatory Durations: Every <testCase> must include an integer duration attribute representing milliseconds. If Xcode omits the duration, the parser should emit 0 rather than omitting the attribute.
    • Project Root Requirement: Because .xcresult bundles typically identify test containers rather than direct source-file paths, you must continue to provide the --project-root flag to allow the parser to resolve test types to their corresponding source files.
    • Compatibility: Standard JUnit output remains compatible and should only change if canonical identifiers are required to correct existing mismatches.
  4. Use xcresultparser to generate reports

    main

    The tool outputs results to stdout. To save the output to a file, use shell redirection.

    Example: Save text output to a file

    xcresultparser -o txt test.xcresult > ~/Desktop/output.txt

    Example: Print colored output to the terminal

    xcresultparser -o cli test.xcresult
  5. Install xcresultparser from binary

    main

    If you are not using Homebrew, you can install the tool manually:

    1. Download xcresultparser.zip from the latest releases.
    2. Unzip and move xcresultparser to your Desktop.
    3. Grant execution permissions:
      chmod +x ~/Desktop/xcresultparser
    4. Move the binary to your system path (e.g., /usr/local/bin/) to use it globally:
      cp ~/Desktop/xcresultparser /usr/local/bin/
    5. Verify the installation by running xcresultparser in your terminal.
    chmod +x ~/Desktop/xcresultparser
    cp ~/Desktop/xcresultparser /usr/local/bin/
    xcresultparser
  6. Configure paths for SonarQube integration

    main

    When using SonarQube, xcresultparser yields absolute paths. To ensure SonarQube can map test classes to actual file paths, you must follow these requirements:

    1. Provide --project-root: The .xcresult bundle only lists tests by class name, not by file. Providing --project-root allows xcresultparser to map class names to file names by searching the directory.
    2. Match sonar.sources: The sonar.sources parameter in your sonar-scanner configuration must be an absolute path that matches the directory where xcodebuild ran.

    Using Relative Paths

    If the .xcresult was created on a different machine, you can use --project-root to convert absolute paths into relative paths. xcresultparser will strip the provided string from the beginning of the pathnames.

    Example: If the path in the xcresult is */Users/alex/work/myApp/Sources/myApp/SomeClass.swift and you run:

    xcresultparser -c -o xml --project-root "work/myApp/" test.xcresult > sonar.xml

    The output path will be converted to Sources/myApp/SomeClass.swift. You can then run sonar-scanner from your project root using Sources as the sonar.sources parameter.

    ./xcresultparser -c -o xml --project-root "work/myApp/" test.xcresult > sonar.xml
  7. Use the xcresultparser CLI

    main

    The xcresultparser command-line tool interprets binary .xcresult files and generates summaries in various formats such as txt, xml, html, md, github, junit, cobertura, warnings, and errors.

    To use it, provide the path to your .xcresult file as a positional argument. You can then use various flags and options to customize the output format, coverage reporting, and filtering.

    # Basic usage
    xcresultparser path/to/your.xcresult
    
    # Example: Generate Cobertura coverage report
    xcresultparser path/to/your.xcresult --output-format cobertura --coverage
    
    # Example: Generate GitHub compatible markdown
    xcresultparser path/to/your.xcresult --output-format github
  8. How to verify Xcode 27 compatibility for xcresultparser

    main

    If you are experiencing issues where JUnit or Sonar failure texts are missing their trailing source location (e.g., failed - message instead of failed - message (File.swift:109)), you may be running on Xcode 27.

    To check if your xcresulttool is emitting the new format (which lacks the file/line prefix in the node name), run the following command against an .xcresult bundle:

    xcrun xcresulttool get test-results tests --path <PATH_TO_YOUR_XCRESULT> \
      | grep -o '"name" : "[^"]*failed[^"]*"' | head -3

    Interpretation:

    • Old Format (Xcode ≤ 26.5): The output contains the file and line, e.g., "name" : "File.swift:109: failed - ...".
    • New Format (Xcode 27): The output contains only the failure message, e.g., "name" : "failed - ...".
    xcrun xcresulttool get test-results tests --path Tests/XcresultparserTests/TestAssets/test.xcresult \
      | grep -o '"name" : "[^"]*failed[^"]*"' | head -3