TechnologiesDeveloper Tools & Diagnostics

Testing

iOSmacOStvOSwatchOSvisionOS

Swift Testing is a library for defining tests and recording attachable values that can be saved as part of a test run. You write tests with the Test type and group them into suites, expressing expectations through Expectation and Confirmation and reporting failures as Issue values that capture their SourceLocation. You refine how tests run by applying traits such as ConditionTrait, ParallelizationTrait, TimeLimitTrait, and Tag, and you attach diagnostic data by conforming to the Attachable protocol and saving an Attachment, including images via AttachableImageFormat. The library also supports exit tests through ExitTest and ExitStatus, and lets you customize how arguments and values are represented with CustomTestArgumentEncodable, CustomTestReflectable, and CustomTestStringConvertible.

Defining Tests and Suites 2

The core types that represent individual tests and the source locations they reference.

  • St
    Test
    A type representing a test or suite.
  • St
    SourceLocation
    A type representing a location in source code.

Checking Expectations 3

Types for validating conditions and confirming that expected events occur during a test.

  • St
    Expectation
    A type describing an expectation that has been evaluated.
  • St
    ExpectationFailedError
    A type describing an error thrown when an expectation fails during
  • St
    Confirmation
    A type that can be used to confirm that an event occurs zero or more times.

Reporting Issues 3

Types that capture and describe failures and other noteworthy events recorded during a test run.

  • St
    Issue
    A type describing a failure or warning which occurred during a test.
  • St
    Comment
    A type that represents a comment related to a test.
  • St
    Bug
    A type that represents a bug report tracked by a test.

Customizing Test Behavior with Traits 9

Traits and trait protocols that refine how, when, and in what scope tests and suites run.

  • Pr
    Trait
    A protocol describing traits that can be added to a test function or to a
  • Pr
    TestTrait
    A protocol describing a trait that you can add to a test function.
  • Pr
    SuiteTrait
    A protocol describing a trait that you can add to a test suite.
  • Pr
    TestScoping
    A protocol that tells the test runner to run custom code before or after it
  • St
    ConditionTrait
    A type that defines a condition which must be satisfied for the testing
  • St
    ParallelizationTrait
    A type that defines whether the testing library runs this test serially
  • St
    TimeLimitTraitiOS 16.0+
    A type that defines a time limit to apply to a test.
  • St
    IssueHandlingTrait
    A type that allows transforming or filtering the issues recorded by a test.
  • St
    Tag
    A type representing a tag that can be applied to a test.

Attaching Diagnostic Data 5

Protocols and types for saving values, wrappers, and images as attachments alongside a test run.

  • Pr
    Attachable
    A protocol describing a type whose instances can be recorded and saved as
  • Pr
    AttachableWrapper
    A protocol describing a type whose instances can be recorded and saved as
  • Pr
    AttachableAsImageiOS 14.0+
    A protocol describing images that can be converted to instances of
  • St
    Attachment
    A type describing values that can be attached to the output of a test run
  • St
    AttachableImageFormatiOS 14.0+
    A type describing image formats supported by the system that can be used

Running Exit Tests 2

Types for running code in a separate process and inspecting how that process terminates.

  • St
    ExitTest
    A type describing an exit test.
  • En
    ExitStatus
    An enumeration describing possible status a process will report on exit.

Representing Arguments and Values 3

Protocols that customize how test arguments and values are encoded, reflected, and described.

  • Pr
    CustomTestArgumentEncodable
    A protocol for customizing how arguments passed to parameterized tests are
  • Pr
    CustomTestReflectable
    A protocol describing types with a custom reflection when presented as part
  • Pr
    CustomTestStringConvertible
    A protocol describing types with a custom string representation when

Type Aliases 1

  • Ty
    KnownIssueMatcher
    A function that is used to match known issues.

Extends 17

ArrayContiguousArrayArraySliceStringSubstringMirrorOptionalClosedRangePartialRangeFromPartialRangeThroughPartialRangeUpToRangeNeverNSImageCGImageCIImageData
← Developer Tools & Diagnostics