---
title: Attachment
framework: testing
role: symbol
role_heading: Structure
path: testing/attachment
---

# Attachment

A type describing values that can be attached to the output of a test run and inspected later by the user.

## Declaration

```swift
struct Attachment<AttachableValue> where AttachableValue : Attachable, AttachableValue : ~Copyable
```

## Mentioned in

Migrating a test from XCTest

## Overview

Overview To create an attachment, you need a value of some type that conforms to Attachable. Initialize an instance of Attachment with that value and, optionally, a preferred filename to use when saving the attachment. To record the attachment, call record(_:sourceLocation:). Alternatively, pass your attachable value directly to record(_:named:sourceLocation:).

## Topics

### Initializers

- [init(_:named:as:sourceLocation:)](testing/attachment/init(_:named:as:sourcelocation:).md)
- [init(_:named:sourceLocation:)](testing/attachment/init(_:named:sourcelocation:).md)
- [init(contentsOf:named:sourceLocation:)](testing/attachment/init(contentsof:named:sourcelocation:).md)
- [init(exporting:as:named:sourceLocation:)](testing/attachment/init(exporting:as:named:sourcelocation:).md)

### Instance Properties

- [attachableValue](testing/attachment/attachablevalue-2tnj5.md)
- [attachableValue](testing/attachment/attachablevalue-vkrw.md)
- [imageFormat](testing/attachment/imageformat.md)
- [preferredName](testing/attachment/preferredname.md)

### Instance Methods

- [withUnsafeBytes(_:)](testing/attachment/withunsafebytes(_:).md)

### Type Methods

- [record(_:named:as:sourceLocation:)](testing/attachment/record(_:named:as:sourcelocation:).md)
- [record(_:named:sourceLocation:)](testing/attachment/record(_:named:sourcelocation:).md)
- [record(_:sourceLocation:)](testing/attachment/record(_:sourcelocation:).md)

### Default Implementations

- [CustomStringConvertible Implementations](testing/attachment/customstringconvertible-implementations.md)

## Relationships

### Conforms To

- [Copyable](swift/copyable.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Escapable](swift/escapable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Attaching values to tests

- [Attachable](testing/attachable.md)
- [AttachableWrapper](testing/attachablewrapper.md)
