RetryAttribute Class

Definition

This attribute is used to set a retry count on a test method in case of failure.

[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=false, Inherited=false)]
public sealed class RetryAttribute : Microsoft.VisualStudio.TestTools.UnitTesting.RetryBaseAttribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=false, Inherited=false)]
public sealed class RetryAttribute : Microsoft.VisualStudio.TestTools.UnitTesting.RetryBaseAttribute
[<System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=false, Inherited=false)>]
type RetryAttribute = class
    inherit RetryBaseAttribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=false, Inherited=false)>]
type RetryAttribute = class
    inherit RetryBaseAttribute
Public NotInheritable Class RetryAttribute
Inherits RetryBaseAttribute
Inheritance
RetryAttribute
Attributes

Remarks

When applied to a test class, the attribute is used as a default for every test method declared on the class. A RetryAttribute placed directly on a test method takes precedence over a class-level one (the method-level value fully replaces the class-level value, regardless of whether it is larger or smaller). The attribute is not inherited: applying it to a base test class does not apply it to derived test classes.

Constructors

Name Description
RetryAttribute(Int32)

Initializes a new instance of the RetryAttribute class with the given number of max retries.

Properties

Name Description
BackoffType

Gets or sets the delay backoff type.

MaxRetryAttempts

Gets the number of retries that the test should make in case of failures. Note that before RetryAttribute is considered, the test was already executed once. This property determines the max number of retries after the first normal run.

MillisecondsDelayBetweenRetries

Gets or sets the delay, in milliseconds, between retries. This delay is also applied after the first run and before the first retry attempt.

Methods

Name Description
ExecuteAsync(RetryContext)

Retries the test method. The details of how retry is done is left to the derived classes. Note that a first run of the method was already executed and failed before this method is called.

(Inherited from RetryBaseAttribute)

Applies to