Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Assert Class

Verifies conditions in unit tests using true/false propositions.

System.Object
  Microsoft.VisualStudio.TestTools.UnitTesting.Assert

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

public final class Assert

The Assert type exposes the following members.

  NameDescription
Public methodStatic memberAreEqual(Object, Object)Verifies that two specified objects are equal. The assertion fails if the objects are not equal.
Public methodStatic memberAreEqual(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 memberAreEqual(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 memberAreEqual(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 memberAreEqual(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 memberAreEqual(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 memberAreEqual(Object, Object, String, 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 memberAreEqual(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 memberAreEqual(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 memberAreEqual(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 memberAreEqual(Double, Double, Double, String, 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 memberAreEqual(Single, Single, Single, String, 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 memberAreEqual(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 memberAreEqual(String, String, Boolean, String, 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 memberAreEqual(String, String, Boolean, CultureInfo, String, 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 memberAreEqual(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 memberAreEqual(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 memberAreEqual(T)(T, T, String, 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 memberAreNotEqual(Object, Object)Verifies that two specified objects are not equal. The assertion fails if the objects are equal.
Public methodStatic memberAreNotEqual(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 memberAreNotEqual(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 memberAreNotEqual(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 memberAreNotEqual(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 memberAreNotEqual(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 memberAreNotEqual(Object, Object, String, 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 memberAreNotEqual(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 memberAreNotEqual(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 memberAreNotEqual(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 memberAreNotEqual(Double, Double, Double, String, 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 memberAreNotEqual(Single, Single, Single, String, 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 memberAreNotEqual(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 memberAreNotEqual(String, String, Boolean, String, 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 memberAreNotEqual(String, String, Boolean, CultureInfo, String, 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 memberAreNotEqual(T)(T, T)Verifies that two specified generic type data are not equal. The assertion fails if they are equal.
Public methodStatic memberAreNotEqual(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 memberAreNotEqual(T)(T, T, String, 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 memberAreNotSame(Object, Object)Verifies that two specified object variables refer to different objects. The assertion fails if they refer to the same object.
Public methodStatic memberAreNotSame(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 memberAreNotSame(Object, Object, String, 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 memberAreSame(Object, Object)Verifies that two specified object variables refer to the same object. The assertion fails if they refer to different objects.
Public methodStatic memberAreSame(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 memberAreSame(Object, Object, String, 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 memberEqualsDetermines whether two objects are equal.
Public methodStatic memberFail()Fails the assertion without checking any conditions.
Public methodStatic memberFail(String)Fails the assertion without checking any conditions. Displays a message.
Public methodStatic memberFail(String, Object[])Fails the assertion without checking any conditions. Displays a message, and applies the specified formatting to it.
Public methodStatic memberInconclusive()Indicates that the assertion cannot be verified.
Public methodStatic memberInconclusive(String)Indicates that the assertion can not be verified. Displays a message.
Public methodStatic memberInconclusive(String, Object[])Indicates that an assertion can not be verified. Displays a message, and applies the specified formatting to it.
Public methodStatic memberIsFalse(Boolean)Verifies that the specified condition is false. The assertion fails if the condition is true.
Public methodStatic memberIsFalse(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 memberIsFalse(Boolean, String, 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 memberIsInstanceOfType(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 memberIsInstanceOfType(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 memberIsInstanceOfType(Object, Type, String, 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 memberIsNotInstanceOfType(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 memberIsNotInstanceOfType(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 memberIsNotInstanceOfType(Object, Type, String, 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 memberIsNotNull(Object)Verifies that the specified object is not a null reference (Nothing in Visual Basic). The assertion fails if it is a null reference (Nothing in Visual Basic).
Public methodStatic memberIsNotNull(Object, String)Verifies that the specified object is not a null reference (Nothing in Visual Basic). The assertion fails if it is a null reference (Nothing in Visual Basic). Displays a message if the assertion fails.
Public methodStatic memberIsNotNull(Object, String, Object[])Verifies that the specified object is not a null reference (Nothing in Visual Basic). The assertion fails if it is a null reference (Nothing in Visual Basic). Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic memberIsNull(Object)Verifies that the specified object is a null reference (Nothing in Visual Basic). The assertion fails if it is not a null reference (Nothing in Visual Basic).
Public methodStatic memberIsNull(Object, String)Verifies that the specified object is a null reference (Nothing in Visual Basic). The assertion fails if it is not a null reference (Nothing in Visual Basic). Displays a message if the assertion fails.
Public methodStatic memberIsNull(Object, String, Object[])Verifies that the specified object is a null reference (Nothing in Visual Basic). The assertion fails if it is not a null reference (Nothing in Visual Basic). Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic memberIsTrue(Boolean)Verifies that the specified condition is true. The assertion fails if the condition is false.
Public methodStatic memberIsTrue(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 memberIsTrue(Boolean, String, 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 memberReplaceNullCharsIn a string, replaces null characters ('\0') with "\\0".
Top

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 noteImportant

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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft