swiftlang / swiftlang/swift-testing

Ability to write tests right in the same file

Open
#795 1 comment 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Swift
Stars
2.2k
Forks
169
Avg merge
1d 18h
Merged PRs (30d)
56

Description

Description

It would be nice if we had the ability to write test in the same file, and not in files far away in a dedicated Tests folder.
This will have some benefits like:

  • The code and the tests are just simply closer apart.
  • We could use access modifiers like fileprivate to test parts of the code in the same file, instead of having to workaround this by @testable importing which makes users have to not use private access modifiers just to be able to test a function. Or using stuff like @_spi.

Languages like Rust do support this.

I saw some discussions about this a few months ago, I think the compiler needs to support better discovery of stuff like tests for this to be possible.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the issue's referenced discussions about placing tests in the same Swift source file and the compiler's test discovery limitations. Define how same-file tests should be discovered and how access modifiers such as fileprivate should behave; the work is done when the requested capability is supported and its behavior is verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.