Skip to main content
The Polly.Testing package provides utilities for testing resilience pipelines, allowing you to inspect the structure and configuration of your pipelines in unit tests.

Installation

Extension Methods

GetPipelineDescriptor

Retrieves a descriptor that describes the structure and strategies of a resilience pipeline.
ResiliencePipeline
required
The pipeline instance to describe
Returns: A ResiliencePipelineDescriptor containing information about the pipeline. Example:

GetPipelineDescriptor<TResult>

Retrieves a descriptor for a generic resilience pipeline.
ResiliencePipeline<TResult>
required
The generic pipeline instance to describe
Returns: A ResiliencePipelineDescriptor containing information about the pipeline. Example:

Descriptor Classes

ResiliencePipelineDescriptor

Describes the structure of a resilience pipeline.

Properties

Strategies Gets the strategies the pipeline is composed of.
  • Type: IReadOnlyList<ResilienceStrategyDescriptor>
FirstStrategy Gets the first strategy of the pipeline. This is a convenience property equivalent to Strategies[0].
  • Type: ResilienceStrategyDescriptor
IsReloadable Gets a value indicating whether the resilience pipeline is reloadable (i.e., supports dynamic reloading).
  • Type: bool
Example:

ResilienceStrategyDescriptor

Provides information about an individual resilience strategy within a pipeline.

Properties

Options Gets the options used by the resilience strategy, if any.
  • Type: ResilienceStrategyOptions?
  • Default: null if the strategy was not created with options
StrategyInstance Gets the strategy instance. This is the actual strategy object that executes the resilience logic.
  • Type: object
Example:

Testing Patterns

Verifying Pipeline Composition

Test that your pipeline contains the expected strategies in the correct order.

Verifying Strategy Options

Test that strategies are configured with the correct options.

Testing Generic Pipelines

Test generic pipelines that handle specific result types.

Testing Reloadable Pipelines

Verify that pipelines registered with dynamic reloading are marked as reloadable.

Testing Strategy Instance Types

Access the actual strategy instance for more detailed testing.

Testing Multiple Strategies

Iterate through all strategies in a complex pipeline.

Integration Testing

Combine testing utilities with integration tests:

Best Practices

  1. Test Pipeline Structure: Always verify that your pipeline contains the expected strategies in the correct order.
  2. Verify Options: Check that strategies are configured with the correct options values.
  3. Test Reloadability: If using dynamic reloading, verify that the IsReloadable property is true.
  4. Use Descriptive Strategy Names: Set the Name property on strategy options to make testing easier.
  5. Combine with Integration Tests: Use descriptors to verify configuration, then test actual execution behavior.
  6. Type Safety: Use pattern matching or type checks to safely access specific option types.

See Also