<!--
{
  "availability" : [
    "Xcode: 16.0.0 -",
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "swift: 6.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Testing",
  "identifier" : "/documentation/Testing/Trait/timeLimit(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Swift Testing",
      "Testing"
    ],
    "preciseIdentifier" : "s:7Testing5TraitPA2A09TimeLimitB0VRszrlE04timeD0yA2E8DurationVFZ"
  },
  "title" : "timeLimit(_:)"
}
-->

# timeLimit(_:)

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

```
static func timeLimit(_ timeLimit: TimeLimitTrait.Duration) -> Self
```

## Parameters

`timeLimit`

The maximum amount of time the test may run for.

## Return Value

An instance of [`TimeLimitTrait`](/documentation/Testing/TimeLimitTrait).

## Discussion

Test timeouts do not support high-precision, arbitrarily short durations
due to variability in testing environments. You express the duration in
minutes, with a minimum duration of one minute.

When you associate this trait with a test, that test must complete within
a time limit of, at most, `timeLimit`. If the test runs longer, the
testing library records a
[`Issue.Kind.timeLimitExceeded(timeLimitComponents:)`](/documentation/Testing/Issue/Kind-swift.enum/timeLimitExceeded(timeLimitComponents:)) issue, which it
treats as a test failure.

The testing library can use a shorter time limit than that specified by
`timeLimit` if you configure it to enforce a maximum per-test limit. When
you configure a maximum per-test limit, the time limit of the test this
trait is applied to is the shorter of `timeLimit` and the maximum per-test
limit. For information on configuring maximum per-test limits, consult the
documentation for the tool you use to run your tests.

If a test is parameterized, this time limit is applied to each of its
test cases individually. If a test has more than one time limit associated
with it, the testing library uses the shortest time limit.

If you apply this trait to a test suite, then it sets the time limit for
each test in the suite, or each test case in parameterized tests in the
suite.
For example, if a suite contains five tests and you apply a time limit trait
with a duration of one minute, then each test in the suite may run for up to
one minute.

---

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)