語言

Assert.Scope 方法

定義

建立一個新的斷言範圍,收集斷言失敗,而非立即丟棄。 當回傳示波器被丟棄時,所有收集的失敗會作為一個 AssertFailedException丟出。

[System.Diagnostics.CodeAnalysis.Experimental("MSTESTEXP", UrlFormat="https://aka.ms/mstest/diagnostics#{0}")]
public static IDisposable Scope();
public static IDisposable Scope();
[<System.Diagnostics.CodeAnalysis.Experimental("MSTESTEXP", UrlFormat="https://aka.ms/mstest/diagnostics#{0}")>]
static member Scope : unit -> IDisposable
static member Scope : unit -> IDisposable
Public Shared Function Scope () As IDisposable

傳回

A IDisposable 表示斷言範圍。

屬性

範例

using (Assert.Scope())
{
    Assert.AreEqual(1, 2);  // collected, not thrown
    Assert.IsTrue(false);   // collected, not thrown
}
// AssertFailedException is thrown here with all collected failures.

適用於