Skip to content

Conversation

@jerryjrchen
Copy link

Link Swift Testing documentation in its test template

Motivation:

This hopefully makes it easier for new users to find relevant documentation for our test framework!

It also matches the existing pattern where XCTest documentation is linked in its respective test template.

Modifications:

  • Add a link to Swift Testing documentation in the test template.
  • Trims some trailing whitespace. Realistically, I don't have much control over this since my editor is respecting the project's .editorconfig's trim_trailing_whitespace = true directive. I can manually put them back if that would be better.

Result:

Default Swift Testing template will include a comment linking to the developer docs.

Testing it locally:

~/scraps/autogen/xx.ZtJsA ❯ /Users/jerrychen/workspace/opensource/swift-package-manager/.build/arm64-apple-macosx/debug/swift-package init
Creating library package: xx.ZtJsA
Creating Package.swift
Creating .gitignore
Creating Sources
Creating Sources/xx.ZtJsA/xx_ZtJsA.swift
Creating Tests/
Creating Tests/xx.ZtJsATests/
Creating Tests/xx.ZtJsATests/xx_ZtJsATests.swift
~/scraps/autogen/xx.ZtJsA ❯ /bin/cat Tests/xx.ZtJsATests/xx_ZtJsATests.swift
import Testing
@testable import xx_ZtJsA

@Test func example() async throws {
    // Write your test here and use APIs like `#expect(...)` to check expected conditions.
    // Swift Testing Documentation
    // https://developer.apple.com/documentation/testing
}

This hopefully makes it easier for new users to find relevant
documentation for our test framework!

It also matches the existing pattern where XCTest documentation is
linked in its respective test template.
@grynspan
Copy link
Contributor

Is there an equivalent link on swift.org we could use?

@jerryjrchen
Copy link
Author

Is there an equivalent link on swift.org we could use?

Closest I could find is https://www.swift.org/documentation/core-libraries/#swift-testing, which transitively links to the Swift Testing GitHub repo.

@jerryjrchen jerryjrchen self-assigned this Nov 12, 2025
@jerryjrchen jerryjrchen added documentation swift package init Package templates command changes labels Nov 12, 2025
@Test func example() async throws {
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
// Swift Testing Documentation
// https://developer.apple.com/documentation/testing
Copy link
Contributor

@bkhouri bkhouri Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (blocking): I love this and completely support it. Though,I have been disappointed (for a lack of a better word) previously while inspecting the Apple XCTest documentation when targeting non-Apple devices as the XCTest API is not identical on macOS and Linux. Although I suspect this is not the case with Swift Testing, my experience has lead me to not have confidence that the developer.apple.com documentation will be valid on non-apple platforms.

Can the link point to the Swift.org Swift Testing API. If that documentation is not published, I would say updating the template is gating upon that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though,I have been disappointed (for a lack of a better word) previously while inspecting the Apple XCTest documentation when targeting non-Apple devices as the XCTest API is not identical on macOS and Linux.

Feel free to open a PR, although I have no idea where you'd do so.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the link point to the Swift.org Swift Testing API. If that documentation is not published, I would say updating the template is gating upon that.

Could we link to swiftpackageindex.com? There's a copy of the documentation hosted there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation swift package init Package templates command changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants