Synergex.TestFramework.Assert
WTSupported in traditional Synergy on Windows
|
|
|
|
namespace Synergex.TestFramework public static class Assert
Unit testing for traditional Synergy projects is a pre-release feature. |
The Synergex.TestFramework.Assert class includes methods you can use to test various conditions in unit tests for traditional Synergy projects. If the condition being tested by an Assert method call is not met, an exception is thrown (Synergex.TestFramework.AssertFailedException or Synergex.TestFramework.AssertInconclusiveException). The Synergex.TestFramework.Assert class is modeled after Microsoft's Assert class (see Microsoft.VisualStudio.TestTools.UnitTesting.Assert), but there are differences. Note the following:
- Numeric comparisons are type agnostic, so logical types are equal regardless of the actual type of the value. For example, an i1 value of 4 is treated as equal to a d4 value of 4.
- If an assertion fails, a message is displayed in the unit test results. Most Assert methods have at least one overload that includes a message parameter, which enables you to specify what the failure message will be (this overrides the default failure message). Additionally, you can use String.Format parameters to insert the value of an object, variable, or expression into message by using the parameters parameter, which is available for all method overloads that have message. See Microsoft documentation on String.Format for more information. For example, the following statement results in the message "Message takes 4 arguments [2,3]. Fourth" if string1 is not equal to string2.
Assert.AreEqual(string1, string2, "Message takes {0} arguments [{1},{2}]. {3,10}", 4, 2, 3, "fourth")
See Unit testing for traditional Synergy for more information on traditional Synergy unit testing.
Methods
AreEqual
public static AreEqual(expectedObj, actualObj)
public static AreEqual(expectedObj, actualObj, message[, parameters])
public static AreEqual(expectedNum, actualNum)
public static AreEqual(expectedNum, actualNum, delta)
public static AreEqual(expectedNum, actualNum, delta, message[, parameters])
public static AreEqual(expectedStr, actualStr, ignoreCase)
public static AreEqual(expectedStr, actualStr, ignoreCase, message[, parameters])
Tests whether the specified objects, numbers, or strings are equal or whether specified numbers are within an allowed difference (delta) of each other. An exception is thrown if the test fails—i.e., if they are not equal or within the allowed difference. If the test fails, a message is displayed in the test results. If message is passed, that string is used for the failure message.
The object, numeric value, or string that the test expects. (@Object, n, System.String)
The object, numeric value, or string that the tested code produces. (@Object, n, System.String)
A string that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used (for example, "Objects are not equal"). (System.String)
String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)
A numeric value specifying the required accuracy of a numeric comparison (i.e., an allowed difference between expectedNum and actualNum). For example, if delta is 2, the values 8 and 6 are considered equal, but 8 and 5 are not. If delta is 0, the test succeeds only if the values are equal. (n)
A Boolean value specifying case-insensitive (true) or case-sensitive (false) comparison. (boolean)
AreNotEqual
public static AreNotEqual(notExpectedObj, actualObj)
public static AreNotEqual(notExpectedObj, actualObj, message[, parameters])
public static AreNotEqual(notExpectedNum, actualNum)
public static AreNotEqual(notExpectedNum, actualNum, delta)
public static AreNotEqual(notExpectedNum, actualNum, delta, message[, parameters])
public static AreNotEqual(notExpectedStr, actualStr, ignorecase)
public static AreNotEqual(notExpectedStr, actualStr, ignorecase, message[, parameters])
Tests whether the specified objects, numbers, or strings are not equal or whether specified numbers are not within an allowed difference (delta) of each other. An exception is thrown if the test fails—i.e., if they are equal or within the allowed difference. If the test fails, a message is displayed in the test results. If message is passed, that string is used for the failure message.
The object, numeric value, or string that is expected to be different than actualObj, actualNum, or actualStr. (@Object, n, System.String)
The object, numeric value, or string that the tested code produces. (@Object, n, System.String)
A message that is displayed in unit test results if the test fails. If message is null or empty, a default message is used. (System.String)
String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)
A numeric value specifying the required accuracy (i.e., an allowed difference) between notExpectedNum and actualNum. For example, if delta is 2, the values 8 and 6 are considered equal, but 8 and 5 are not. If delta is 0, the test succeeds only if the values are equal. (n)
A Boolean value specifying case-insensitive (true) or case-sensitive (false) comparison. (boolean)
AreNotSame
public static AreNotSame(notExpectedObj, actualObj)
public static AreNotSame(notExpectedObj, actualObj, message[, parameters])
Tests whether the specified object variables refer to different objects. If they refer to the same object, the test fails. If the test fails, an exception is thrown and a message is displayed in the test results. If message is passed, that string is used for the failure message.
The object that is expected to be different than actualObj. (@Object)
The object that the tested code produces. (@Object)
A message that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used (System.String)
String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)
AreSame
public static AreSame(expectedObj, actualObj)
public static AreSame(expectedObj, actualObj, message[, parameters])
Tests whether the specified object variables refer to the same object. The assertion fails if they refer to different objects. If the assertion fails, an exception is thrown and a message is displayed in the test results. If message is passed, that string is used for the failure message.
The object that is expected to be the same as actualObj. (@Object)
The object that the tested code produces. (@Object)
A message that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used. (System.String)
String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)
Fail
public static Fail()
public static Fail(message[, parameters])
Throws AssertFailedException without any test (without checking conditions) and displays a failure message in test results. If message is passed, that string is used for the failure message.
A message that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used. (System.String)
String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)
Inconclusive
public static Inconclusive()
public static Inconclusive(message[, parameters])
Throws AssertInconclusiveException without any test (without checking conditions) and displays a failure message in test results. If message is passed, that string is used for the failure message.
A message that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used. (System.String)
String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)
IsFalse
public static IsFalse(condition)
public static IsFalse(condition, message[, parameters])
Tests whether the specified condition is false. If the condition is true, the test fails, an exception is thrown, and a message is displayed in test results. If message is passed, that string is used for the failure message.
The condition to test. (boolean)
A message that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used. (System.String)
String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)
IsNotNull
public static IsNotNull(object)
public static IsNotNull(object, message[, parameters])
Tests whether the specified object is not null. If it is null, the test fails, an exception is thrown, and a message is displayed in the test results. If message is passed, that string is used for the failure message.
An object. (@Object)
A message that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used. (System.String)
String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)
IsNull
public static IsNull(object)
public static IsNull(object, message[, parameters])
Tests whether the specified object is null. If it is not null, the test fails, an exception is thrown, and a message is displayed in test results. If message is passed, that string is used for the failure message.
An object. (@Object)
A message that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used. (System.String)
String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)
ReplaceNullChars
public static ReplaceNullChars(originalString), System.String
Replaces null characters ('\0') in a string with "\\0" and returns the resulting string (System.String).
The string whose null characters ('\0') will be converted to "\\0". (System.String)
IsTrue
public static IsTrue(condition)
public static IsTrue(condition, message[, parameters])
Tests whether the specified condition is true. If the condition is false, the test fails, an exception is thrown, and a message is displayed in test results. If message is passed, that string is used for the failure message.
The condition to test. (boolean)
A message that is displayed in unit test results if the assertion fails. If message is null or empty, a default message is used. (System.String)
String.Format parameters that enable you to insert the value of an object, variable, or expression into message. See the introductory discussion for the Assert class above for more information. ([#]@Object)