java.lang.Object | |
↳ | org.junit.Assert |
A set of assertion methods useful for writing tests. Only failed assertions
are recorded. These methods can be used directly:
Assert.assertEquals(...)
, however, they read better if they
are referenced through static import:
import static org.junit.Assert.*; ... assertEquals(...);
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Protect constructor since it is a static only class
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Asserts that two char arrays are equal.
| |||||||||||
Asserts that two object arrays are equal.
| |||||||||||
Asserts that two char arrays are equal.
| |||||||||||
Asserts that two double arrays are equal.
| |||||||||||
Asserts that two byte arrays are equal.
| |||||||||||
Asserts that two short arrays are equal.
| |||||||||||
Asserts that two byte arrays are equal.
| |||||||||||
Asserts that two int arrays are equal.
| |||||||||||
Asserts that two float arrays are equal.
| |||||||||||
Asserts that two object arrays are equal.
| |||||||||||
Asserts that two double arrays are equal.
| |||||||||||
Asserts that two int arrays are equal.
| |||||||||||
Asserts that two long arrays are equal.
| |||||||||||
Asserts that two short arrays are equal.
| |||||||||||
Asserts that two float arrays are equal.
| |||||||||||
Asserts that two long arrays are equal.
| |||||||||||
Asserts that two doubles or floats are equal to within a positive delta.
| |||||||||||
Asserts that two longs are equal.
| |||||||||||
Asserts that two objects are equal.
| |||||||||||
This method is deprecated.
Use
assertEquals(String message, double expected, double actual, double epsilon)
instead
| |||||||||||
This method is deprecated.
use assertArrayEquals
| |||||||||||
This method is deprecated.
use assertArrayEquals
| |||||||||||
This method is deprecated.
Use
assertEquals(double expected, double actual, double epsilon)
instead
| |||||||||||
Asserts that two doubles or floats are equal to within a positive delta.
| |||||||||||
Asserts that two objects are equal.
| |||||||||||
Asserts that two longs are equal.
| |||||||||||
Asserts that a condition is false.
| |||||||||||
Asserts that a condition is false.
| |||||||||||
Asserts that an object isn't null.
| |||||||||||
Asserts that an object isn't null.
| |||||||||||
Asserts that two objects do not refer to the same object.
| |||||||||||
Asserts that two objects do not refer to the same object.
| |||||||||||
Asserts that an object is null.
| |||||||||||
Asserts that an object is null.
| |||||||||||
Asserts that two objects refer to the same object.
| |||||||||||
Asserts that two objects refer to the same object.
| |||||||||||
Asserts that
actual satisfies the condition specified by
matcher . | |||||||||||
Asserts that
actual satisfies the condition specified by
matcher . | |||||||||||
Asserts that a condition is true.
| |||||||||||
Asserts that a condition is true.
| |||||||||||
Fails a test with the given message.
| |||||||||||
Fails a test with no message.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Protect constructor since it is a static only class
Asserts that two char arrays are equal. If they are not, an AssertionError is thrown with the given message.
message | the identifying message for the AssertionError (null
okay) |
---|---|
expecteds | char array with expected values. |
actuals | char array with actual values |
ArrayComparisonFailure |
---|
Asserts that two object arrays are equal. If they are not, an
AssertionError is thrown. If expected
and
actual
are null
, they are considered
equal.
expecteds | Object array or array of arrays (multi-dimensional array) with expected values |
---|---|
actuals | Object array or array of arrays (multi-dimensional array) with actual values |
Asserts that two char arrays are equal. If they are not, an AssertionError is thrown.
expecteds | char array with expected values. |
---|---|
actuals | char array with actual values |
Asserts that two double arrays are equal. If they are not, an AssertionError is thrown.
expecteds | double array with expected values. |
---|---|
actuals | double array with actual values |
Asserts that two byte arrays are equal. If they are not, an AssertionError is thrown.
expecteds | byte array with expected values. |
---|---|
actuals | byte array with actual values |
Asserts that two short arrays are equal. If they are not, an AssertionError is thrown with the given message.
message | the identifying message for the AssertionError (null
okay) |
---|---|
expecteds | short array with expected values. |
actuals | short array with actual values |
ArrayComparisonFailure |
---|
Asserts that two byte arrays are equal. If they are not, an AssertionError is thrown with the given message.
message | the identifying message for the AssertionError (null
okay) |
---|---|
expecteds | byte array with expected values. |
actuals | byte array with actual values |
ArrayComparisonFailure |
---|
Asserts that two int arrays are equal. If they are not, an AssertionError is thrown with the given message.
message | the identifying message for the AssertionError (null
okay) |
---|---|
expecteds | int array with expected values. |
actuals | int array with actual values |
ArrayComparisonFailure |
---|
Asserts that two float arrays are equal. If they are not, an AssertionError is thrown with the given message.
message | the identifying message for the AssertionError (null
okay) |
---|---|
expecteds | float array with expected values. |
actuals | float array with actual values |
ArrayComparisonFailure |
---|
Asserts that two object arrays are equal. If they are not, an
AssertionError is thrown with the given message. If
expecteds
and actuals
are null
,
they are considered equal.
message | the identifying message for the AssertionError (null
okay) |
---|---|
expecteds | Object array or array of arrays (multi-dimensional array) with expected values. |
actuals | Object array or array of arrays (multi-dimensional array) with actual values |
ArrayComparisonFailure |
---|
Asserts that two double arrays are equal. If they are not, an AssertionError is thrown with the given message.
message | the identifying message for the AssertionError (null
okay) |
---|---|
expecteds | double array with expected values. |
actuals | double array with actual values |
ArrayComparisonFailure |
---|
Asserts that two int arrays are equal. If they are not, an AssertionError is thrown.
expecteds | int array with expected values. |
---|---|
actuals | int array with actual values |
Asserts that two long arrays are equal. If they are not, an AssertionError is thrown.
expecteds | long array with expected values. |
---|---|
actuals | long array with actual values |
Asserts that two short arrays are equal. If they are not, an AssertionError is thrown.
expecteds | short array with expected values. |
---|---|
actuals | short array with actual values |
Asserts that two float arrays are equal. If they are not, an AssertionError is thrown.
expecteds | float array with expected values. |
---|---|
actuals | float array with actual values |
Asserts that two long arrays are equal. If they are not, an AssertionError is thrown with the given message.
message | the identifying message for the AssertionError (null
okay) |
---|---|
expecteds | long array with expected values. |
actuals | long array with actual values |
ArrayComparisonFailure |
---|
Asserts that two doubles or floats are equal to within a positive delta.
If they are not, an AssertionError is thrown with the given
message. If the expected value is infinity then the delta value is
ignored. NaNs are considered equal:
assertEquals(Double.NaN, Double.NaN, *)
passes
message | the identifying message for the AssertionError (null
okay) |
---|---|
expected | expected value |
actual | the value to check against expected |
delta | the maximum delta between expected and
actual for which both numbers are still
considered equal.
|
Asserts that two longs are equal. If they are not, an AssertionError is thrown with the given message.
message | the identifying message for the AssertionError (null
okay) |
---|---|
expected | long expected value. |
actual | long actual value |
Asserts that two objects are equal. If they are not, an
AssertionError without a message is thrown. If
expected
and actual
are null
,
they are considered equal.
expected | expected value |
---|---|
actual | the value to check against expected
|
This method is deprecated.
Use
assertEquals(String message, double expected, double actual, double epsilon)
instead
This method is deprecated.
use assertArrayEquals
Asserts that two object arrays are equal. If they are not, an
AssertionError is thrown with the given message. If
expecteds
and actuals
are null
,
they are considered equal.
message | the identifying message for the AssertionError (null
okay) |
---|---|
expecteds | Object array or array of arrays (multi-dimensional array) with expected values. |
actuals | Object array or array of arrays (multi-dimensional array) with actual values |
This method is deprecated.
use assertArrayEquals
Asserts that two object arrays are equal. If they are not, an
AssertionError is thrown. If expected
and
actual
are null
, they are considered
equal.
expecteds | Object array or array of arrays (multi-dimensional array) with expected values |
---|---|
actuals | Object array or array of arrays (multi-dimensional array) with actual values |
This method is deprecated.
Use
assertEquals(double expected, double actual, double epsilon)
instead
Asserts that two doubles or floats are equal to within a positive delta.
If they are not, an AssertionError is thrown. If the expected
value is infinity then the delta value is ignored.NaNs are considered
equal: assertEquals(Double.NaN, Double.NaN, *)
passes
expected | expected value |
---|---|
actual | the value to check against expected |
delta | the maximum delta between expected and
actual for which both numbers are still
considered equal.
|
Asserts that two objects are equal. If they are not, an
AssertionError is thrown with the given message. If
expected
and actual
are null
,
they are considered equal.
message | the identifying message for the AssertionError (null
okay) |
---|---|
expected | expected value |
actual | actual value |
Asserts that two longs are equal. If they are not, an AssertionError is thrown.
expected | expected long value. |
---|---|
actual | actual long value |
Asserts that a condition is false. If it isn't it throws an AssertionError with the given message.
message | the identifying message for the AssertionError (null
okay) |
---|---|
condition | condition to be checked |
Asserts that a condition is false. If it isn't it throws an AssertionError without a message.
condition | condition to be checked |
---|
Asserts that an object isn't null. If it is an AssertionError is thrown with the given message.
message | the identifying message for the AssertionError (null
okay) |
---|---|
object | Object to check or null
|
Asserts that an object isn't null. If it is an AssertionError is thrown.
object | Object to check or null
|
---|
Asserts that two objects do not refer to the same object. If they do refer to the same object, an AssertionError without a message is thrown.
unexpected | the object you don't expect |
---|---|
actual | the object to compare to unexpected
|
Asserts that two objects do not refer to the same object. If they do refer to the same object, an AssertionError is thrown with the given message.
message | the identifying message for the AssertionError (null
okay) |
---|---|
unexpected | the object you don't expect |
actual | the object to compare to unexpected
|
Asserts that an object is null. If it isn't an AssertionError is thrown.
object | Object to check or null
|
---|
Asserts that an object is null. If it is not, an AssertionError is thrown with the given message.
message | the identifying message for the AssertionError (null
okay) |
---|---|
object | Object to check or null
|
Asserts that two objects refer to the same object. If they are not the same, an AssertionError without a message is thrown.
expected | the expected object |
---|---|
actual | the object to compare to expected
|
Asserts that two objects refer to the same object. If they are not, an AssertionError is thrown with the given message.
message | the identifying message for the AssertionError (null
okay) |
---|---|
expected | the expected object |
actual | the object to compare to expected
|
Asserts that actual
satisfies the condition specified by
matcher
. If not, an AssertionError is thrown with
the reason and information about the matcher and failing value. Example:
: assertThat("Help! Integers don't work", 0, is(1)); // fails: // failure message: // Help! Integers don't work // expected: is <1> // got value: <0> assertThat("Zero is one", 0, is(not(1))) // passes
reason | additional information about the error |
---|---|
actual | the computed value being compared |
matcher | an expression, built of Matchers, specifying allowed values |
JUnitMatchers
Asserts that actual
satisfies the condition specified by
matcher
. If not, an AssertionError is thrown with
information about the matcher and failing value. Example:
assertThat(0, is(1)); // fails: // failure message: // expected: is <1> // got value: <0> assertThat(0, is(not(1))) // passes
actual | the computed value being compared |
---|---|
matcher | an expression, built of Matchers, specifying allowed values |
JUnitMatchers
Asserts that a condition is true. If it isn't it throws an AssertionError with the given message.
message | the identifying message for the AssertionError (null
okay) |
---|---|
condition | condition to be checked |
Asserts that a condition is true. If it isn't it throws an AssertionError without a message.
condition | condition to be checked |
---|
Fails a test with the given message.
message | the identifying message for the AssertionError (null
okay) |
---|
Fails a test with no message.