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

# Trait

A protocol describing traits that can be added to a test function or to a
test suite.

```
protocol Trait : Sendable
```

## Overview

The testing library defines a number of traits that can be added to test
functions and to test suites. Define your own traits by
creating types that conform to [`TestTrait`](/documentation/Testing/TestTrait) or [`SuiteTrait`](/documentation/Testing/SuiteTrait):

- [`TestTrait`](/documentation/Testing/TestTrait): Conform to this type in traits that you add to test
  functions.
- [`SuiteTrait`](/documentation/Testing/SuiteTrait): Conform to this type in traits that you add to test
  suites.

You can add a trait that conforms to both [`TestTrait`](/documentation/Testing/TestTrait) and [`SuiteTrait`](/documentation/Testing/SuiteTrait)
to test functions and test suites.

## Topics

### Enabling and disabling tests

[`enabled(if:_:sourceLocation:)`](/documentation/Testing/Trait/enabled(if:_:sourceLocation:))

Constructs a condition trait that disables a test if it returns `false`.

[`enabled(_:sourceLocation:_:)`](/documentation/Testing/Trait/enabled(_:sourceLocation:_:))

Constructs a condition trait that disables a test if it returns `false`.

[`disabled(_:sourceLocation:)`](/documentation/Testing/Trait/disabled(_:sourceLocation:))

Constructs a condition trait that disables a test unconditionally.

[`disabled(if:_:sourceLocation:)`](/documentation/Testing/Trait/disabled(if:_:sourceLocation:))

Constructs a condition trait that disables a test if its value is true.

[`disabled(_:sourceLocation:_:)`](/documentation/Testing/Trait/disabled(_:sourceLocation:_:))

Constructs a condition trait that disables a test if its value is true.

### Controlling how tests are run

[`timeLimit(_:)`](/documentation/Testing/Trait/timeLimit(_:))

Construct a time limit trait that causes a test to time out if it runs for
too long.

[`serialized`](/documentation/Testing/Trait/serialized)

A trait that serializes the test to which it is applied.

### Categorizing tests and adding information

[`tags(_:)`](/documentation/Testing/Trait/tags(_:))

Construct a list of tags to apply to a test.

[`comments`](/documentation/Testing/Trait/comments)

The user-provided comments for this trait.

### Associating bugs

[`bug(_:_:)`](/documentation/Testing/Trait/bug(_:_:))

Constructs a bug to track with a test.

[`bug(_:id:_:)`](/documentation/Testing/Trait/bug(_:id:_:)-10yf5)

Constructs a bug to track with a test.

[`bug(_:id:_:)`](/documentation/Testing/Trait/bug(_:id:_:)-3vtpl)

Constructs a bug to track with a test.

### Running code before and after a test or suite

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

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

[`scopeProvider(for:testCase:)`](/documentation/Testing/Trait/scopeProvider(for:testCase:))

Get this trait’s scope provider for the specified test and optional test
case.

[`TestScopeProvider`](/documentation/Testing/Trait/TestScopeProvider)

The type of the test scope provider for this trait.

[`prepare(for:)`](/documentation/Testing/Trait/prepare(for:))

Prepare to run the test that has this trait.



---

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)