---
title: "Understanding Output Relay"
language: "en"
url: "https://docs.testany.io/en/docs/understanding-output-relay/"
markdown_url: "https://docs.testany.io/en/docs/understanding-output-relay.md"
translation: "https://docs.testany.io/zh/docs/understanding-output-relay.md"
last_updated: "2026-03-26T15:39:24+08:00"
---

# Understanding Output Relay

## What is Output Relay?

Output Relay is a mechanism that allows one test case to pass data to another test case within the same test pipeline. Think of it as a "data handoff" between tests.

**Simple Analogy**: Imagine a relay race where runners pass a baton. In Output Relay:
- The **baton** is a variable (like a token, ID, or URL)
- The **first runner** (Output Case) generates and passes the data
- The **next runner** (Input Case) receives and uses that data


> **Tip**
>
> Output Relay maintains test independence while enabling data dependencies. Each test case remains atomic and self-contained, but can share outputs when orchestrated in a pipeline.


## Why Do You Need Output Relay?

### The Problem: Hardcoded Dependencies

Without Output Relay, you might write tests like this:

```python
# Test A: Login and get token
def test_login():
    token = api.login("user", "pass")
    # Token is lost after this test ends!

# Test B: Get user profile (BROKEN - no token!)
def test_get_profile():
    token = "???"  # Where does this come from?
    api.get_profile(token)
```

Common workarounds (all problematic):
- **Hardcode tokens** → Breaks when tokens expire
- **Combine into one giant test** → Hard to maintain, slow to debug
- **Use global variables** → Tests become interdependent and fragile

### The Solution: Output Relay

With Output Relay, Test A can pass the token to Test B:

![Output Relay Simple Flow](https://docs.testany.io/docs/images/en/output-relay-simple-flow.svg)

Each test stays independent, but data flows through the pipeline.

## Core Concepts

### Output Case vs Input Case

| Concept | Description | Example |
|---------|-------------|---------|
| **Output Case** | A test case that produces data for other tests | Login test that generates an access token |
| **Input Case** | A test case that consumes data from other tests | API test that uses the token to make requests |


> **Info**
>
> A test case can be both an Output Case and an Input Case simultaneously. For example, Test B might receive a token from Test A, then pass a user ID to Test C.


### Relay Variable

A Relay Variable is a named variable that:
1. Is declared in the Output Case's environment variables (on Testany Platform)
2. Is populated by the Output Case's code at runtime
3. Is consumed by the Input Case as an environment variable

### Data Flow in a Pipeline

Here's how data flows through a typical pipeline with Output Relay:

![Output Relay Pipeline Flow](https://docs.testany.io/docs/images/en/output-relay-pipeline-flow.svg)

In this example:
- **Case A** outputs `ACCESS_TOKEN`
- **Case B** inputs `ACCESS_TOKEN`, outputs `USER_ID`
- **Case C** inputs both `ACCESS_TOKEN` (from A) and `USER_ID` (from B)

## End-to-End Setup Overview

Setting up Output Relay involves **three steps** across two systems:

![Output Relay Setup Overview](https://docs.testany.io/docs/images/en/output-relay-setup-overview.svg)

### Step 1: Write Code to Output Data

In your Output Case, use the `TESTANY_OUTPUT_RELAY_SERVICE` environment variable to POST data:

```python
# Python example
import os
import requests

relay_service = os.environ.get('TESTANY_OUTPUT_RELAY_SERVICE')
requests.post(relay_service, json={
    'ACCESS_TOKEN': 'eyJhbGciOiJIUzI1NiIs...'
})
```

### Step 2: Mark Variable as Relay on Platform

On the Test Case detail page, add an environment variable and click the **relay icon** to mark it as a relay variable.

### Step 3: Configure Pipeline YAML

In your pipeline definition, use `relay` to connect cases:

```yaml
kind: rule/v1.3
spec:
  rules:
    - run: A1B2C3D4  # Login case
    - run: E5F6A7B8  # Profile case
      relay:
        - key: ACCESS_TOKEN
          refKey: A1B2C3D4/ACCESS_TOKEN  # Reference login case's output
```


> **Note**
>
> For all new pipelines, `rule/v1.3` is the recommended version. `rule/v1.2` can still run, but it does not provide case-level parallel execution.


## Constraints and Limitations

### Relay Only Works with Passed Cases


> **Warning**
>
> You can only relay data from a test case that **passed**. If the Output Case fails, aborts, or times out, its relay data is not available.


In `rule/v1.3`, this also means the test script that consumes relay data cannot be in a relationship where it might start at the same time as the test script that provides relay data. The platform requires the test script that provides relay data to finish before the test script that consumes relay data starts.

This means you **cannot** configure:
```yaml
# INVALID - relay with whenFailed
- run: E5F6A7B8  # Input case
  whenFailed: A1B2C3D4  # Output case failed, no reliable data
  relay:
    - key: TOKEN
      refKey: A1B2C3D4/TOKEN
```

### No Circular Dependencies

The platform automatically detects and rejects circular relay configurations:

```yaml
# INVALID - circular dependency
- run: A1B2C3D4  # Case A
  relay:
    - key: X
      refKey: E5F6A7B8/Y
- run: E5F6A7B8  # Case B
  relay:
    - key: Y
      refKey: A1B2C3D4/X  # Error: circular dependency
```

### Performance Testing Not Supported

Output Relay is designed for **functional testing** only. It is not available for performance/load testing scenarios.

## Next Steps

Now that you understand the concepts, proceed to the implementation guides:

| If you want to... | Read this |
|-------------------|-----------|
| Write relay code in your test scripts | [Managing Test Case with Relay Case](https://docs.testany.io/en/docs/managing-test-case-with-relay-case.md) |
| Configure relay in pipeline YAML | [Build your tests more robust & flexible with Output Relay](https://docs.testany.io/en/docs/build-your-tests-more-robust-flexible-with-output-.md) |
| Learn pipeline YAML syntax | [Pipeline YAML Schema Reference](https://docs.testany.io/en/docs/pipeline-yaml-schema-reference.md) |

## Quick Reference

| Term | Definition |
|------|------------|
| Output Relay | Feature that passes data between test cases in a pipeline |
| Output Case | Test case that produces relay data |
| Input Case | Test case that consumes relay data |
| Relay Variable | Named variable passed from Output Case to Input Case |
| `TESTANY_OUTPUT_RELAY_SERVICE` | Environment variable containing the relay service URL |
| `relay.refKey` | Pipeline YAML field that references another case's output |


> **Still confused?** The key insight is that Output Relay separates **data generation** (in code) from **data routing** (in pipeline YAML). Your test code only needs to POST data to the relay service. The platform handles the routing based on your pipeline configuration.

## Glossary terms on this page

- [Output relay](https://docs.testany.io/en/docs/glossary.md#output-relay)
- [Test Case](https://docs.testany.io/en/docs/glossary.md#test-case)
- [Test Pipeline](https://docs.testany.io/en/docs/glossary.md#test-pipeline)
- [Test Script](https://docs.testany.io/en/docs/glossary.md#test-script)
- [Environment](https://docs.testany.io/en/docs/glossary.md#environment)
