Partager via


StringAssert Class

Verifies true/false propositions associated with strings in unit tests.

Inheritance Hierarchy

Object
  Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert

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

Syntax

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

Methods

  Name Description
Public methodStatic member Contains(String, String) Verifies that the first string contains the second string. This method is case sensitive.
Public methodStatic member Contains(String, String, String) Verifies that the first string contains the second string. Displays a message if the assertion fails. This method is case sensitive.
Public methodStatic member Contains(String, String, String, array<Object[]) Verifies that the first string contains the second string. Displays a message if the assertion fails, and applies the specified formatting to it. This method is case sensitive.
Public methodStatic member DoesNotMatch(String, Regex) Verifies that the specified string does not match the regular expression.
Public methodStatic member DoesNotMatch(String, Regex, String) Verifies that the specified string does not match the regular expression. Displays a message if the assertion fails.
Public methodStatic member DoesNotMatch(String, Regex, String, array<Object[]) Verifies that the specified string does not match the regular expression. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member EndsWith(String, String) Verifies that the first string ends with the second string. This method is case sensitive.
Public methodStatic member EndsWith(String, String, String) Verifies that the first string ends with the second string. Displays a message if the assertion fails. This method is case sensitive.
Public methodStatic member EndsWith(String, String, String, array<Object[]) Verifies that the first string ends with the second string. Displays a message if the assertion fails, and applies the specified formatting to it. This method is case sensitive.
Public methodStatic member Matches(String, Regex) Verifies that the specified string matches the regular expression.
Public methodStatic member Matches(String, Regex, String) Verifies that the specified string matches the regular expression. Displays a message if the assertion fails.
Public methodStatic member Matches(String, Regex, String, array<Object[]) Verifies that the specified string matches the regular expression. Displays a message if the assertion fails, and applies the specified formatting to it.
Public methodStatic member StartsWith(String, String) Verifies that the first string begins with the second string. This method is case sensitive.
Public methodStatic member StartsWith(String, String, String) Verifies that the first string begins with the second string. Displays a message if the assertion fails. This method is case sensitive.
Public methodStatic member StartsWith(String, String, String, array<Object[]) Verifies that the first string begins with the second string. Displays a message if the assertion fails, and applies the specified formatting to it. This method is case sensitive.

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.

If the condition being verified is not true, the assertion fails.

Important

The StringAssert 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