swift-testing icon indicating copy to clipboard operation
swift-testing copied to clipboard

Ability to write tests right in the same file

Open MahdiBM opened this issue 1 year ago • 1 comments

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.

MahdiBM avatar Nov 02 '24 15:11 MahdiBM

Tracked internally as rdar://112339873.

grynspan avatar Nov 04 '24 20:11 grynspan