语言

RetryAttribute 类

定义

此属性用于在失败时对测试方法设置重试计数。

[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
继承
RetryAttribute
属性

注解

应用于测试类时,该属性将用作在类上声明的每个测试方法的默认值。 RetryAttribute直接放置在测试方法上的优先于类级别 1(方法级值完全替换类级别值,无论该值是大还是小)。 属性不继承:将其应用于基测试类不会将其应用于派生的测试类。

在至少一次 Microsoft.VisualStudio.TestTools.UnitTesting.TestResult 尝试具有 Failed 或 Timeout 结果时执行重试。 一旦尝试不生成失败且没有超时结果,重试就会停止。 对于数据驱动测试(每次尝试的多个结果),这是一个聚合规则:结果 Inconclusive (例如,当测试调用 Assert.Inconclusive()时)仅当其同级测试均未导致同级尝试失败或超时时结束重试;否则仍重试尝试。 上次尝试的结果将成为测试的最终结果。

此属性在单个测试主机运行中重试。 它独立于 Microsoft.Testing.Extensions.Retry--retry-failed-tests 业务流程协调程序,它重新调用整个测试主机。 当两者同时启用时,尝试计数相乘(测试可以运行到 (MaxRetryAttempts + 1) x (--retry-failed-tests + 1) 数次),因此请避免将它们组合在一起,除非这是预期。

构造函数

名称 说明
RetryAttribute(Int32)

使用给定的最大重试次数初始化类的新实例 RetryAttribute 。

属性

名称 说明
BackoffType

获取或设置延迟退避类型。

MaxRetryAttempts

获取测试在失败时应进行的重试次数。 请注意,在考虑 RetryAttribute 之前,测试已执行一次。 此属性确定第一次正常运行后的最大重试次数。

MillisecondsDelayBetweenRetries

获取或设置重试之间的延迟(以毫秒为单位)。 在第一次运行和第一次重试尝试之前,也会应用此延迟。

方法

名称 说明
ExecuteAsync(RetryContext)

重试测试方法。 重试方式的详细信息留给派生类。 请注意,在调用此方法之前,已执行并失败了该方法的第一次运行。

(继承自 RetryBaseAttribute)

适用于