<!--
{
  "availability" : [
    "Swift: 6.1.0 -",
    "Xcode: 16.3.0 -",
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "swift: 6.0.0 -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Testing",
  "identifier" : "/documentation/Testing/TestScoping",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Swift Testing"
    ],
    "preciseIdentifier" : "s:7Testing11TestScopingP"
  },
  "title" : "TestScoping"
}
-->

# TestScoping

A protocol that tells the test runner to run custom code before or after it
runs a test suite or test function.

```
protocol TestScoping : Sendable
```

## Overview

Provide custom scope for tests by implementing the
[`scopeProvider(for:testCase:)`](/documentation/Testing/Trait/scopeProvider(for:testCase:)) method, returning a type that
conforms to this protocol. Create a custom scope to consolidate common
set-up and tear-down logic for tests which have similar needs, which allows
each test function to focus on the unique aspects of its test.

## Relationships

### Conforming Types

[`IssueHandlingTrait`](/documentation/Testing/IssueHandlingTrait)

[`ParallelizationTrait`](/documentation/Testing/ParallelizationTrait)

### Inherits From

[`Sendable`](/documentation/Swift/Sendable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)