Assert Class
Verifies conditions in unit tests using true/false propositions.
Inheritance Hierarchy
System.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 | |
---|---|---|
AreEqual(Object, Object) | Verifies that two specified objects are equal. The assertion fails if the objects are not equal. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
AreNotEqual(Object, Object) | Verifies that two specified objects are not equal. The assertion fails if the objects are equal. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
AreNotEqual<T>(T, T) | Verifies that two specified generic type data are not equal. The assertion fails if they are equal. | |
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. | |
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. | |
AreNotSame(Object, Object) | Verifies that two specified object variables refer to different objects. The assertion fails if they refer to the same object. | |
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. | |
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. | |
AreSame(Object, Object) | Verifies that two specified object variables refer to the same object. The assertion fails if they refer to different objects. | |
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. | |
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. | |
Equals | Determines whether two objects are equal. | |
Fail() | Fails the assertion without checking any conditions. | |
Fail(String) | Fails the assertion without checking any conditions. Displays a message. | |
Fail(String, array<Object[]) | Fails the assertion without checking any conditions. Displays a message, and applies the specified formatting to it. | |
Inconclusive() | Indicates that the assertion cannot be verified. | |
Inconclusive(String) | Indicates that the assertion cannot be verified. Displays a message. | |
Inconclusive(String, array<Object[]) | Indicates that an assertion cannot be verified. Displays a message, and applies the specified formatting to it. | |
IsFalse(Boolean) | Verifies that the specified condition is false. The assertion fails if the condition is true. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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). | |
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. | |
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. | |
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). | |
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. | |
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. | |
IsTrue(Boolean) | Verifies that the specified condition is true. The assertion fails if the condition is false. | |
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. | |
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. | |
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 a 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