Skip to content

Parse allure.id from Swift Testing comments#93

Open
BorisLys wants to merge 8 commits into
eroshenkoam:mainfrom
BorisLys:feature/swift-testing-allure-id
Open

Parse allure.id from Swift Testing comments#93
BorisLys wants to merge 8 commits into
eroshenkoam:mainfrom
BorisLys:feature/swift-testing-allure-id

Conversation

@BorisLys

@BorisLys BorisLys commented May 26, 2026

Copy link
Copy Markdown

Summary

Swift Testing serializes trait comments into ActionTestSummary.documentation._values[].content._value, separately from activitySummaries. The existing parser only inspected activity titles (the XCTest path via XCTContext.runActivity), so allure.id traits on Swift Testing tests were silently dropped.

This change reads the documentation field on each test summary and extracts allure.id:<n> into the AS_ID label using the same regex as the XCTest path. XCTest behavior is unchanged.

Scope: only allure.id. Other allure.* patterns (name/description/label/link) are intentionally out of scope for this PR.

Usage

Define a Swift Testing trait that wraps the id as a Comment:

import Testing

public struct AllureIdTrait: TestTrait, SuiteTrait {
    private let id: Int

    public var comments: [Comment] {
        [Comment(rawValue: "allure.id:\(id)")]
    }

    public init(_ id: Int) {
        self.id = id
    }
}

extension Trait where Self == AllureIdTrait {
    public static func allureId(_ id: Int) -> Self {
        .init(id)
    }
}

Apply it to a test:

@Test(.allureId(1234))
func example() {
    // ...
}

After running the test suite and exporting the xcresult:

xcresults export Test.xcresult ./allure-results

The resulting *-result.json now contains the AS_ID label:

{
  "name": "example()",
  "fullName": "SwiftRadioTests/example()",
  "labels": [
    { "name": "AS_ID", "value": "1234" },
    { "name": "suite", "value": "SwiftRadioTests" }
  ]
}

Test plan

  • Verified on a real Xcode 16 xcresult bundle containing a Swift Testing test annotated with .allureId(1234)AS_ID=1234 appears in the exported JSON
  • Regression: XCTest test using XCTContext.runActivity(named: "allure.id:N") still produces the same AS_ID label as before

BorisLys and others added 8 commits May 26, 2026 16:20
Swift Testing serializes trait comments into
ActionTestSummary.documentation._values[].content._value, separately
from activitySummaries. The existing parser only inspected activity
titles, so allure.id traits on Swift Testing tests were dropped.

Read the documentation field and extract allure.id:<n> into the AS_ID
label using the same regex as the XCTest path.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Swift Testing serializes parametrized test arguments into
ActionTestSummary.arguments._values[]. Each argument combination
produces a separate summary node with the same identifier, causing
all combos to share an identical historyId and collapse in Allure.

- Parse arguments._values[] into Allure Parameter objects
  (name = parameter.label, value = value.description)
- Extend getHistoryId to append ordered argument values so each
  combination gets a distinct, stable historyId

Gated on node.has("arguments") — XCTest and non-parametrized
Swift Testing tests are unaffected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Jackson uses reflection to serialize allure-model POJOs. Parameter
was missing from the reflect-config, so its name/value fields were
inaccessible in the native binary and serialized as empty objects {}.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Swift Testing stores display names separately from function names:
- @test("Example test name") -> ActionTestSummary.summary._value
- @suite("Suite name")       -> ActionTestSummaryGroup.summary._value

Use summary as test name when present (fallback to function name for
tests without a display name). Override suite label from the group's
summary field so @suite display names appear in Allure.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant