Assert.Scope Method

Definition

Creates a new assertion scope that collects assertion failures instead of throwing them immediately. When the returned scope is disposed, all collected failures are thrown as a single AssertFailedException.

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

Returns

An IDisposable representing the assertion scope.

Attributes

Examples

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

Applies to