Condividi tramite


Assert Class

Verifies conditions in unit tests using true/false propositions.

Inheritance Hierarchy

Object
  Microsoft.VisualStudio.TestTools.UnitTesting.Assert

Namespace:  Microsoft.VisualStudio.TestTools.UnitTesting
Assembly:  Microsoft.VisualStudio.QualityTools.UnitTestFramework (in Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll)

Syntax

'Declaration
Public NotInheritable Class Assert
public static class Assert
public ref class Assert abstract sealed
[<AbstractClass>]
[<Sealed>]
type Assert =  class end
public final class Assert

The Assert type exposes the following members.

Methods

  Name Description
Public methodStatic member AreEqual(Object, Object) Verifies that two specified objects are equal. The assertion fails if the objects are not equal.
Public methodStatic member AreEqual(Double, Double, Double) Verifies that two specified doubles are equal, or within the specified accuracy of each other. The assertion fails if they are not within the specified accuracy of each other.
Public methodStatic member AreEqual(Object, Object, String) Verifies that two specified objects are equal. The assertion fails if the objects are not equal. Displays a message if the assertion fails.
Public methodStatic member AreEqual(Single, Single, Single) Verifies that two specified singles are equal, or within the specified accuracy of each other. The assertion fails if they are not within the specified accuracy of each other.
Public methodStatic member AreEqual(String, String, Boolean) Verifies that two specified strings are equal, ignoring case or not as specified. The assertion fails if they are not equal.
Public methodStatic member AreEqual(Double, Double, Double, String) Verifies that two specified doubles are equal, or within the specified accuracy of each other. The assertion fails if they are not within the specified accuracy of each other. Displays a message if the assertion fails.
Public methodStatic member AreEqual(Object, Object, String, array<Object[]) Verifies that two specified objects are equal. The assertion fails if the objects are not equal. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member AreEqual(Single, Single, Single, String) Verifies that two specified singles are equal, or within the specified accuracy of each other. The assertion fails if they are not within the specified accuracy of each other. Displays a message if the assertion fails.
Public methodStatic member AreEqual(String, String, Boolean, CultureInfo) Verifies that two specified strings are equal, ignoring case or not as specified, and using the culture info specified. The assertion fails if they are not equal.
Public methodStatic member AreEqual(String, String, Boolean, String) Verifies that two specified strings are equal, ignoring case or not as specified. The assertion fails if they are not equal. Displays a message if the assertion fails.
Public methodStatic member AreEqual(Double, Double, Double, String, array<Object[]) Verifies that two specified doubles are equal, or within the specified accuracy of each other. The assertion fails if they are not within the specified accuracy of each other. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member AreEqual(Single, Single, Single, String, array<Object[]) Verifies that two specified singles are equal, or within the specified accuracy of each other. The assertion fails if they are not within the specified accuracy of each other. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member AreEqual(String, String, Boolean, CultureInfo, String) Verifies that two specified strings are equal, ignoring case or not as specified, and using the culture info specified. The assertion fails if they are not equal. Displays a message if the assertion fails.
Public methodStatic member AreEqual(String, String, Boolean, String, array<Object[]) Verifies that two specified strings are equal, ignoring case or not as specified. The assertion fails if they are not equal. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member AreEqual(String, String, Boolean, CultureInfo, String, array<Object[]) Verifies that two specified strings are equal, ignoring case or not as specified, and using the culture info specified. The assertion fails if they are not equal. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member AreEqual<T>(T, T) Verifies that two specified generic type data are equal by using the equality operator. The assertion fails if they are not equal.
Public methodStatic member AreEqual<T>(T, T, String) Verifies that two specified generic type data are equal by using the equality operator. The assertion fails if they are not equal. Displays a message if the assertion fails.
Public methodStatic member AreEqual<T>(T, T, String, array<Object[]) Verifies that two specified generic type data are equal by using the equality operator. The assertion fails if they are not equal. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member AreNotEqual(Object, Object) Verifies that two specified objects are not equal. The assertion fails if the objects are equal.
Public methodStatic member AreNotEqual(Double, Double, Double) Verifies that two specified doubles are not equal, and not within the specified accuracy of each other. The assertion fails if they are equal or within the specified accuracy of each other.
Public methodStatic member AreNotEqual(Object, Object, String) Verifies that two specified objects are not equal. The assertion fails if the objects are equal. Displays a message if the assertion fails.
Public methodStatic member AreNotEqual(Single, Single, Single) Verifies that two specified singles are not equal, and not within the specified accuracy of each other. The assertion fails if they are equal or within the specified accuracy of each other.
Public methodStatic member AreNotEqual(String, String, Boolean) Verifies that two specified strings are not equal, ignoring case or not as specified. The assertion fails if they are equal.
Public methodStatic member AreNotEqual(Double, Double, Double, String) Verifies that two specified doubles are not equal, and not within the specified accuracy of each other. The assertion fails if they are equal or within the specified accuracy of each other. Displays a message if the assertion fails.
Public methodStatic member AreNotEqual(Object, Object, String, array<Object[]) Verifies that two specified objects are not equal. The assertion fails if the objects are equal. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member AreNotEqual(Single, Single, Single, String) Verifies that two specified singles are not equal, and not within the specified accuracy of each other. The assertion fails if they are equal or within the specified accuracy of each other. Displays a message if the assertion fails.
Public methodStatic member AreNotEqual(String, String, Boolean, CultureInfo) Verifies that two specified strings are not equal, ignoring case or not as specified, and using the culture info specified. The assertion fails if they are equal.
Public methodStatic member AreNotEqual(String, String, Boolean, String) Verifies that two specified strings are not equal, ignoring case or not as specified. The assertion fails if they are equal. Displays a message if the assertion fails.
Public methodStatic member AreNotEqual(Double, Double, Double, String, array<Object[]) Verifies that two specified doubles are not equal, and not within the specified accuracy of each other. The assertion fails if they are equal or within the specified accuracy of each other. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member AreNotEqual(Single, Single, Single, String, array<Object[]) Verifies that two specified singles are not equal, and not within the specified accuracy of each other. The assertion fails if they are equal or within the specified accuracy of each other. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member AreNotEqual(String, String, Boolean, CultureInfo, String) Verifies that two specified strings are not equal, ignoring case or not as specified, and using the culture info specified. The assertion fails if they are equal. Displays a message if the assertion fails.
Public methodStatic member AreNotEqual(String, String, Boolean, String, array<Object[]) Verifies that two specified strings are not equal, ignoring case or not as specified. The assertion fails if they are equal. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member AreNotEqual(String, String, Boolean, CultureInfo, String, array<Object[]) Verifies that two specified strings are not equal, ignoring case or not as specified, and using the culture info specified. The assertion fails if they are equal. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member AreNotEqual<T>(T, T) Verifies that two specified generic type data are not equal. The assertion fails if they are equal.
Public methodStatic member AreNotEqual<T>(T, T, String) Verifies that two specified generic type data are not equal. The assertion fails if they are equal. Displays a message if the assertion fails.
Public methodStatic member AreNotEqual<T>(T, T, String, array<Object[]) Verifies that two specified generic type data are not equal. The assertion fails if they are equal. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member AreNotSame(Object, Object) Verifies that two specified object variables refer to different objects. The assertion fails if they refer to the same object.
Public methodStatic member AreNotSame(Object, Object, String) Verifies that two specified object variables refer to different objects. The assertion fails if they refer to the same object. Displays a message if the assertion fails.
Public methodStatic member AreNotSame(Object, Object, String, array<Object[]) Verifies that two specified object variables refer to different objects. The assertion fails if they refer to the same object. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member AreSame(Object, Object) Verifies that two specified object variables refer to the same object. The assertion fails if they refer to different objects.
Public methodStatic member AreSame(Object, Object, String) Verifies that two specified object variables refer to the same object. The assertion fails if they refer to different objects. Displays a message if the assertion fails.
Public methodStatic member AreSame(Object, Object, String, array<Object[]) Verifies that two specified object variables refer to the same object. The assertion fails if they refer to different objects. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member Equals Determines whether two objects are equal.
Public methodStatic member Fail() Fails the assertion without checking any conditions.
Public methodStatic member Fail(String) Fails the assertion without checking any conditions. Displays a message.
Public methodStatic member Fail(String, array<Object[]) Fails the assertion without checking any conditions. Displays a message, and applies the specified formatting to it.
Public methodStatic member Inconclusive() Indicates that the assertion cannot be verified.
Public methodStatic member Inconclusive(String) Indicates that the assertion can not be verified. Displays a message.
Public methodStatic member Inconclusive(String, array<Object[]) Indicates that an assertion can not be verified. Displays a message, and applies the specified formatting to it.
Public methodStatic member IsFalse(Boolean) Verifies that the specified condition is false. The assertion fails if the condition is true.
Public methodStatic member IsFalse(Boolean, String) Verifies that the specified condition is false. The assertion fails if the condition is true. Displays a message if the assertion fails.
Public methodStatic member IsFalse(Boolean, String, array<Object[]) Verifies that the specified condition is false. The assertion fails if the condition is true. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member IsInstanceOfType(Object, Type) Verifies that the specified object is an instance of the specified type. The assertion fails if the type is not found in the inheritance hierarchy of the object.
Public methodStatic member IsInstanceOfType(Object, Type, String) Verifies that the specified object is an instance of the specified type. The assertion fails if the type is not found in the inheritance hierarchy of the object. Displays a message if the assertion fails.
Public methodStatic member IsInstanceOfType(Object, Type, String, array<Object[]) Verifies that the specified object is an instance of the specified type. The assertion fails if the type is not found in the inheritance hierarchy of the object. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member IsNotInstanceOfType(Object, Type) Verifies that the specified object is not an instance of the specified type. The assertion fails if the type is found in the inheritance hierarchy of the object.
Public methodStatic member IsNotInstanceOfType(Object, Type, String) Verifies that the specified object is not an instance of the specified type. The assertion fails if the type is found in the inheritance hierarchy of the object. Displays a message if the assertion fails.
Public methodStatic member IsNotInstanceOfType(Object, Type, String, array<Object[]) Verifies that the specified object is not an instance of the specified type. The assertion fails if the type is found in the inheritance hierarchy of the object. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member IsNotNull(Object) Verifies that the specified object is not nulla null reference (Nothing in Visual Basic). The assertion fails if it is nulla null reference (Nothing in Visual Basic).
Public methodStatic member IsNotNull(Object, String) Verifies that the specified object is not nulla null reference (Nothing in Visual Basic). The assertion fails if it is nulla null reference (Nothing in Visual Basic). Displays a message if the assertion fails.
Public methodStatic member IsNotNull(Object, String, array<Object[]) Verifies that the specified object is not nulla null reference (Nothing in Visual Basic). The assertion fails if it is nulla null reference (Nothing in Visual Basic). Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member IsNull(Object) Verifies that the specified object is nulla null reference (Nothing in Visual Basic). The assertion fails if it is not nulla null reference (Nothing in Visual Basic).
Public methodStatic member IsNull(Object, String) Verifies that the specified object is nulla null reference (Nothing in Visual Basic). The assertion fails if it is not nulla null reference (Nothing in Visual Basic). Displays a message if the assertion fails.
Public methodStatic member IsNull(Object, String, array<Object[]) Verifies that the specified object is nulla null reference (Nothing in Visual Basic). The assertion fails if it is not nulla null reference (Nothing in Visual Basic). Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member IsTrue(Boolean) Verifies that the specified condition is true. The assertion fails if the condition is false.
Public methodStatic member IsTrue(Boolean, String) Verifies that the specified condition is true. The assertion fails if the condition is false. Displays a message if the assertion fails.
Public methodStatic member IsTrue(Boolean, String, array<Object[]) Verifies that the specified condition is true. The assertion fails if the condition is false. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member ReplaceNullChars In a string, replaces null characters ('\0') with "\\0".

Top

Remarks

This class contains a set of static methods that evaluate a Boolean condition. If this condition evaluates to true, the assertion passes.

An assertion verifies an assumption of truth for compared conditions. The assertion is central to the unit test. The Assert class provides many static methods for verifying suppositions of truth. If the condition being verified is not true, the assertion fails.

Important

The Assert class throws an AssertFailedException to signal a failure. This exception should not be captured. This exception is handled by the unit test engine to indicate an assert failure.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Microsoft.VisualStudio.TestTools.UnitTesting Namespace

Other Resources

Using the Assert Classes