Swift pitch would put tests inside library targets
Colocated tests would drop the separate-target rule and strip test-only code from release builds with a custom availability domain.
Jerry has pitched colocated tests for Swift, a change that would let library targets keep tests next to the code they exercise instead of in a required separate test target.
That split has been a fixture of Swift packages. Adding or finding tests means another target and, in Xcode, often a scheme switch. A separate target also cannot see private or fileprivate declarations, so authors widen visibility or invent workarounds. Under the proposal, posted on the Swift forums, a library would opt in with a test option on its target, import Swift Testing, and write suites in the same module. A custom Testing availability domain would mark test-only symbols. Testing's own APIs and macros such as @Test would carry the annotation automatically; authors would mark their own helpers. Distribution builds would compile that code out.
Reviewers who already write this way in Go and Rust welcomed the layout. One, who had discussed scope with Jerry, said colocated tests would cover most unit tests and many acceptance tests in feature-oriented projects, while integration and smoke tests would still belong in separate targets so those suites stay grouped. Testing private members, that reviewer added, is better than some workarounds but often a signal that the design should change, not a habit to encourage.
The mechanism drew harder questions. Generalized availability domains have not passed Swift Evolution. tshortli, who works on that feature, said the domains will be re-pitched with this use case as a motivation, and that today's implementation can already enable or disable a Testing domain through compiler flags the build system passes down. Others argued the Package.swift opt-in should become the default once the feature is proven, and asked whether a helper that touches Testing would still crash ordinary executables that merely depend on a library, a failure that happens today even if the executable never imports Testing. Another reviewer worried that large suites would still be type-checked in release builds and could invalidate cached dependents. tshortli said code behind an unavailable Testing domain would be treated as statically unreachable and skipped after type checking, so later optimization stages would not spend time on it.