Class

XCTAttachment

Data from a test method’s execution, such as a file, image, screenshot, data blob, or zip archive.

Declaration

@interface XCTAttachment : NSObject

Topics

Creating Attachments from Data

+ attachmentWithData:

Creates an attachment containing the provided data payload.

+ attachmentWithData:uniformTypeIdentifier:

Creates an attachment containing the provided data payload, with a custom UTI.

- initWithUniformTypeIdentifier:name:payload:userInfo:

Creates an attachment containing the provided data payload, optionally with a custom UTI, name, and user-provided metadata dictionary.

+ attachmentWithUniformTypeIdentifier:name:payload:userInfo:

Creates an attachment containing the provided data payload, optionally with a custom UTI, name, and user-provided metadata dictionary.

Creating Attachments from Files and Folders

+ attachmentWithContentsOfFileAtURL:

Creates an attachment from the contents of an existing file on disk.

+ attachmentWithContentsOfFileAtURL:uniformTypeIdentifier:

Creates an attachment from the contents of an existing file on disk, with a custom UTI.

+ attachmentWithCompressedContentsOfDirectoryAtURL:

Creates an attachment containing a zipped archive of an existing directory on disk.

Creating Attachments from Images and Screenshots

+ attachmentWithImage:

Creates an attachment containing a PNG representation of the provided image.

+ attachmentWithImage:quality:

Creates an attachment containing a representation of the provided image at the requested image quality.

+ attachmentWithScreenshot:

Creates an attachment containing a PNG representation of the provided screenshot.

+ attachmentWithScreenshot:quality:

Creates an attachment containing a representation of the provided screenshot at the requested image quality.

XCUIScreenshot

A captured image of a screen, app, or UI element state.

XCTImageQuality

Compression quality options for image-based attachments.

Creating Attachments from Objects

+ attachmentWithPlistObject:

Creates an attachment from an object that can be represented in an XML property list.

+ attachmentWithArchivableObject:

Creates an attachment from an object that conforms to NSSecureCoding.

+ attachmentWithArchivableObject:uniformTypeIdentifier:

Creates an attachment from an object that conforms to NSSecureCoding, with a custom UTI.

Creating Attachments from Strings

+ attachmentWithString:

Creates an attachment containing the provided string.

Setting an Attachment's Lifetime

lifetime

Indicates whether the attachment is kept or discarded when its associated test passes.

XCTAttachmentLifetime

The possible lifetime values for a test attachment.

Attachment Metadata

name

The attachment’s name, or nil if the attachment is unnamed.

uniformTypeIdentifier

The Uniform Type Identifier (UTI) of the data represented by the attachment.

userInfo

User-provided metadata associated with the attachment.

Relationships

Inherits From

Conforms To

See Also

Attachments

Adding Attachments to Tests and Activities

Use attachments to store a test’s output data for later analysis.