Assert Class
Contains methods to assert various conditions with test methods, such as whether two values are the same, a condition is true, or a variable is null.
The following are methods for Assert.
-
areEqual(expected, actual, msg)
Asserts that the first two arguments are the same.
-
Asserts that the two arguments are the same.
-
areNotEqual(notExpected, actual, msg)
Asserts that the first two arguments aren’t the same.
-
areNotEqual(notExpected, actual)
Asserts that the two arguments aren’t the same.
-
Immediately return a fatal error that causes code execution to halt.
-
Immediately return a fatal error that causes code execution to halt.
-
Asserts that the specified condition is
false. -
Asserts that the specified condition is
false. -
isInstanceOfType(instance, expectedType, msg)
Asserts that the instance is of the specified type.
-
isInstanceOfType(instance, expectedType)
Asserts that the instance is of the specified type.
-
isNotInstanceOfType(instance, notExpectedType, msg)
Asserts that the instance isn’t of the specified type.
-
isNotInstanceOfType(instance, notExpectedType)
Asserts that the instance isn’t of the specified type.
-
Asserts that the value isn’t null.
-
Asserts that the value isn’t null.
-
Asserts that the value is null.
-
Asserts that the value is null.
-
Asserts that the specified condition is
true. -
Asserts that the specified condition is
true.
Asserts that the first two arguments are the same.
public static void areEqual(Object expected, Object actual, String msg)
- expected: Type: Object Expected value.
- actual: Type: Object Actual value.
- msg: Type: String (Optional) Custom message returned as part of the error message.
Type: void
If the first two arguments aren’t the same, a fatal error is returned that causes code execution to halt.
You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.
Asserts that the two arguments are the same.
public static void areEqual(Object expected, Object actual)
- expected: Type: Object Expected value.
- actual: Type: Object Actual value.
Type: void
If the two arguments aren’t the same, a fatal error is returned that causes code execution to halt.
You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.
Asserts that the first two arguments aren’t the same.
public static void areNotEqual(Object notExpected, Object actual, String msg)
- notExpected: Type: Object Value that’s not expected.
- actual: Type: Object Actual value.
- msg: Type: String (Optional) Custom message returned as part of the error message.
Type: void
If the first two arguments are the same, a fatal error is returned that causes code execution to halt.
You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.
Asserts that the two arguments aren’t the same.
public static void areNotEqual(Object notExpected, Object actual)
- notExpected: Type: Object Value that’s not expected.
- actual: Type: Object Actual value.
Type: void
If the two arguments are the same, a fatal error is returned that causes code execution to halt.
You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.
Immediately return a fatal error that causes code execution to halt.
public static void fail(String msg)
- msg: Type: String (Optional) Custom message returned as part of the error message.
Type: void
Commonly used in a try/catch block test case where an exception is expected to be thrown. You can’t, however, catch the assertion failure in the try/catch block even though it’s logged as an exception.
Immediately return a fatal error that causes code execution to halt.
public static void fail()
Type: void
Commonly used in a try/catch block test case where an exception is expected to be thrown. You can’t, however, catch the assertion failure in the try/catch block even though it’s logged as an exception.
Asserts that the specified condition is false.
public static void isFalse(Boolean condition, String msg)
- condition: Type: Boolean Condition you’re checking to determine if it’s
false. - msg: Type: String (Optional) Custom message returned as part of the error message.
Type: void
If the condition is true, a fatal error is returned that causes code execution to halt.
You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.
Asserts that the specified condition is false.
public static void isFalse(Boolean condition)
- condition: Type: Boolean Condition you’re checking to determine if it’s
false.
Type: void
If the condition is true, a fatal error is returned that causes code execution to halt.
You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.
Asserts that the instance is of the specified type.
public static void isInstanceOfType(Object instance, System.Type expectedType, String msg)
- instance: Type: Object Instance whose type you’re checking.
- expectedType: Type: System.Type Expected type.
- msg: Type: String (Optional) Custom message returned as part of the error message.
Type: void
If the instance isn’t of the specified type, a fatal error is returned that causes code execution to halt.
You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.
Asserts that the instance is of the specified type.
public static void isInstanceOfType(Object instance, System.Type expectedType)
- instance: Type: Object Instance whose type you’re checking.
- expectedType: Type: System.Type Expected type.
Type: void
If the instance isn’t of the specified type, a fatal error is returned that causes code execution to halt.
You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.
Asserts that the instance isn’t of the specified type.
public static void isNotInstanceOfType(Object instance, System.Type notExpectedType, String msg)
- instance: Type: Object Instance whose type you’re checking.
- notExpectedType: Type: System.Type Type that’s not expected.
- msg: Type: String (Optional) Custom message returned as part of the error message.
Type: void
If the instance is of the specified type, a fatal error is returned that causes code execution to halt.
You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.
Asserts that the instance isn’t of the specified type.
public static void isNotInstanceOfType(Object instance, System.Type notExpectedType)
- instance: Type: Object Instance whose type you’re checking.
- notExpectedType: Type: System.Type Type that’s not expected.
Type: void
If the instance is of the specified type, a fatal error is returned that causes code execution to halt.
You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.
Asserts that the value isn’t null.
public static void isNotNull(Object value, String msg)
- value: Type: Object Value you’re checking to determine if it’s not null.
- msg: Type: String (Optional) Custom message returned as part of the error message.
Type: void
If the value is null, a fatal error is returned that causes code execution to halt.
You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.
Asserts that the value isn’t null.
public static void isNotNull(Object value)
- value: Type: Object Value you’re checking to determine if it’s not null.
Type: void
If the value is null, a fatal error is returned that causes code execution to halt.
You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.
Asserts that the value is null.
public static void isNull(Object value, String msg)
- value: Type: Object Value you’re checking to determine if it’s null.
- msg: Type: String (Optional) Custom message returned as part of the error message.
Type: void
If the value isn’t null, a fatal error is returned that causes code execution to halt.
You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.
Asserts that the value is null.
public static void isNull(Object value)
- value: Type: Object Value you’re checking to determine if it’s null.
Type: void
If the value isn’t null, a fatal error is returned that causes code execution to halt.
You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.
Asserts that the specified condition is true.
public static void isTrue(Boolean condition, String msg)
- condition: Type: Boolean Condition you’re checking to determine if it’s
true. - msg: Type: String (Optional) Custom message returned as part of the error message.
Type: void
If the specified condition is false, a fatal error is returned that causes code execution to halt.
You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.
Asserts that the specified condition is true.
public static void isTrue(Boolean condition)
- condition: Type: Boolean Condition you’re checking to determine if it’s
true.
Type: void
If the specified condition is false, a fatal error is returned that causes code execution to halt.
You can’t catch an assertion failure using a try/catch block even though it’s logged as an exception.