Adding 'Test diamonds' to Xcode with a macro

I'm currently writing a macro which outputs Swift Testing code:

// Macro code ...

@MainActor
@SnapshotSuite
struct MySuite {
    func makeView() -> some View {
        Text("a view")
    }
}

which expands to...

// Expanded macro code ...

@MainActor
@Suite
struct _GeneratedSnapshotSuite {

    @MainActor
    @Test(.tags(.snapshots))
    func assertSnapshotMakeView() async throws {
        let generator = SnapshotGenerator(
            testName: "makeView",
            traits: [
    			.theme(.all),
    			.sizes(devices: .iPhoneX, fitting: .widthAndHeight),
    			.record(false),
    		],
            configuration: .none,
            makeValue: {
                MySuite().makeView()
            },
            fileID: #fileID,
            filePath: #filePath,
            line: 108,
            column: 5
        )

        await __assertSnapshot(generator: generator)
    }
}

In short, this macro creates snapshot tests from a function.

This all works but I'm finding a couple of limitations, potentially with how Macros are expanded in Swift.

  • Xcode diamonds are not visible
  • The snapshots tag isn't discovered

There are a couple of things worth noting though:

  • The suites and tests are discovered in Xcode's Test Navigator each time Xcode runs tests (cmd + u) - although they need to rerun to be updated.
  • I manually add a @Suite in my code as well as my @SnapshotSuite to all of the suites.
  • (The tags never seem to be available though)

Couple of questions on this:

  • Is this a known issue?
  • Are there any workarounds?

I do wonder if there's a workaround for showing the diamonds with XCTest APIs such as:

Not to be "that guy", but the test diamonds rarely appear in Xcode when I'm writing actual straightforward tests.

There might not be anything wrong with what you're doing; it could just be Xcode being its usual unreliable self.

I find with Swift Testing (especially in my smaller projects) the diamonds are super reliable now.

In my case the above is a repeatable issue where wrapping the code in macros always fails and adding @Suite brings them in again.

I'll give that a go, thanks for the tip!