# Testing: test code shared by several test targets

**URL:** <https://forums.swift.org/t/testing-test-code-shared-by-several-test-targets/84544>\
**Category:** Using Swift\
**Tags:** testing\
**Created:** [February 3, 2026, 6:34pm UTC](https://forums.swift.org/t/testing-test-code-shared-by-several-test-targets/84544 "2026-02-03T18:34:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sspringer](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sspringer](https://forums.swift.org/u/sspringer)\
**Post date:** [February 3, 2026, 6:34pm UTC](https://forums.swift.org/t/testing-test-code-shared-by-several-test-targets/84544/1 "2026-02-03T18:34:22Z")

</div>

I would like to know if it is possible to have shared code (that imports `Testing`) for testing, that can be used by test target that do real tests? I cannot define a test target for it, because test targets cannot import other test targets (it seems to work with SPM outside Xcode, but shouldn’t this work the same by now?), and defining a library for that has analog difficulties.

BTW is it possible to run a specific test target via the command line (it is possible from within Xcode)?

---

<div class="post-metadata">

**Author:** ![maximkrouk](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maximkrouk/32/33394_2.png) [@maximkrouk](https://forums.swift.org/u/maximkrouk)\
**Post date:** [February 5, 2026, 6:19am UTC](https://forums.swift.org/t/testing-test-code-shared-by-several-test-targets/84544/2 "2026-02-05T06:19:21Z")

</div>

You should be able to use basic targets and conditional compilation, you can take a look at [this](https://github.com/pointfreeco/swift-snapshot-testing/blob/main/Sources/SnapshotTesting/Internal/RecordIssue.swift) part of [snapshot-testing](https://github.com/pointfreeco/swift-snapshot-testing) for example. And if you expect `Testing` to always be available in your environment, you can even merge checks into one top-level check:

```swift
// File in a basic target
// You can name it MyPackageTestSupport for example

#if canImport(Testing)
import Testing

func runSharedTests() async throws {
  #expect(true != false)
}
#endif

```

To run specific test target from the command line try

```bash
swift test --filter <#your-target#>

```

_`swift test --help` output related to `--filter` option:_

```swift
--filter <filter> Run test cases that match a regular expression, Format: '<test-target>.<test-case>' or '<test-target>.<test-case>/<test>'.

```
