<!--
{
  "availability" : [
    "Xcode: 16.0.0 -",
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "swift: 6.0.0 -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Testing",
  "identifier" : "/documentation/Testing/CustomTestArgumentEncodable/encodeTestArgument(to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift Testing"
    ],
    "preciseIdentifier" : "s:7Testing27CustomTestArgumentEncodableP06encodecD02toyqd___tKs7EncoderRd__lF"
  },
  "title" : "encodeTestArgument(to:)"
}
-->

# encodeTestArgument(to:)

Encode this test argument.

```
func encodeTestArgument(to encoder: some Encoder) throws
```

## Parameters

`encoder`

The encoder to write data to.

## Discussion> Throws: Any error encountered during encoding.

The encoded form of a test argument should be stable and unique to allow
re-running specific test cases of a parameterized test function. For
optimal performance, large values which are not necessary to uniquely
identify the test argument later should be omitted. Encoded values do not
need to be human-readable.

For more information on how to implement this function, see the
documentation for [`Encodable`](https://developer.apple.com/documentation/swift/encodable).

---

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)