<!--
{
  "documentType" : "article",
  "framework" : "Testing",
  "identifier" : "/documentation/Testing/Traits",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Traits"
}
-->

# Traits

Annotate test functions and suites, and customize their behavior.

## Overview

Pass built-in traits to test functions or suite types to comment, categorize,
classify, and modify the runtime behavior of test suites and test functions.
Implement the [`TestTrait`](/documentation/Testing/TestTrait), and [`SuiteTrait`](/documentation/Testing/SuiteTrait) protocols to create your own
types that customize the behavior of your tests.

## Topics

### Customizing runtime behaviors

[Enabling and disabling tests](/documentation/Testing/EnablingAndDisabling)

Conditionally enable or disable individual tests before they run.

[Limiting the running time of tests](/documentation/Testing/LimitingExecutionTime)

Set limits on how long a test can run for until it fails.

[`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.

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

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

### Running tests serially or in parallel

[Running tests serially or in parallel](/documentation/Testing/Parallelization)

Control whether tests run serially or in parallel.

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

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

### Annotating tests

[Adding tags to tests](/documentation/Testing/AddingTags)

Use tags to provide semantic information for organization, filtering, and customizing appearances.

[Adding comments to tests](/documentation/Testing/AddingComments)

Add comments to provide useful information about tests.

[Associating bugs with tests](/documentation/Testing/AssociatingBugs)

Associate bugs uncovered or verified by tests.

[Interpreting bug identifiers](/documentation/Testing/BugIdentifiers)

Examine how the testing library interprets bug identifiers provided by developers.

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

Declare a tag that can be applied to a test function or test suite.

[`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.

### Handling issues

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

Constructs an trait that transforms issues recorded by a test.

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

Constructs a trait that filters issues recorded by a test.

### Creating custom traits

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

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

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

A protocol describing a trait that you can add to a test function.

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

A protocol describing a trait that you can add to a test 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.

### Supporting types

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

A type that represents a bug report tracked by a test.

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

A type that represents a comment related to a test.

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

A type that defines a condition which must be satisfied for the testing
library to enable a test.

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

A type that allows transforming or filtering the issues recorded by a test.

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

A type that defines whether the testing library runs this test serially
or in parallel.

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

A type representing a tag that can be applied to a test.

[`Tag.List`](/documentation/Testing/Tag/List)

A type representing one or more tags applied to a test.

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

A type that defines a time limit to apply to a test.



---

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)