Assert (JUnit API).pdf

(234 KB) Pobierz
7.12.2018
Assert (JUnit API)
Overview Package
Class
Tree Deprecated Index Help
PREV CLASS NEXT CLASS
SUMMARY: NESTED | FIELD |
CONSTR
|
METHOD
FRAMES
NO FRAMES
All Classes
DETAIL: FIELD |
CONSTR
|
METHOD
org.junit
Class Assert
java.lang.Object
org.junit.Assert
public class
Assert
extends java.lang.Object
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(...);
See Also:
AssertionError
Constructor Summary
protected
Assert()
Protect constructor since it is a static only class
Method Summary
static void
assertArrayEquals(byte[] expecteds,
byte[] actuals)
Asserts that two byte arrays are equal.
static void
assertArrayEquals(char[] expecteds,
char[] actuals)
Asserts that two char arrays are equal.
static void
assertArrayEquals(int[] expecteds,
int[] actuals)
Asserts that two int arrays are equal.
static void
assertArrayEquals(long[] expecteds,
long[] actuals)
Asserts that two long arrays are equal.
static void
assertArrayEquals(java.lang.Object[] expecteds,
java.lang.Object[] actuals)
Asserts that two object arrays are equal.
static void
assertArrayEquals(short[] expecteds,
short[] actuals)
Asserts that two short arrays are equal.
static void
assertArrayEquals(java.lang.String message,
byte[] expecteds, byte[] actuals)
Asserts that two byte arrays are equal.
static void
assertArrayEquals(java.lang.String message,
char[] expecteds, char[] actuals)
Asserts that two char arrays are equal.
static void
assertArrayEquals(java.lang.String message,
int[] expecteds, int[] actuals)
Asserts that two int arrays are equal.
static void
assertArrayEquals(java.lang.String message,
long[] expecteds, long[] actuals)
Asserts that two long arrays are equal.
http://junit.sourceforge.net/javadoc/org/junit/Assert.html#assertFalse(java.lang.String, boolean)
1/12
7.12.2018
Assert (JUnit API)
static void
assertArrayEquals(java.lang.String message,
java.lang.Object[] expecteds,
java.lang.Object[] actuals)
Asserts that two object arrays are equal.
static void
assertArrayEquals(java.lang.String message,
short[] expecteds, short[] actuals)
Asserts that two short arrays are equal.
static void
assertEquals(double expected,
double actual)
Deprecated.
Use
assertEquals(double expected, double actual, double epsilon)
instead
static void
assertEquals(double expected,
double actual, double delta)
Asserts that two doubles or floats are equal to within a positive delta.
static void
assertEquals(long expected,
long actual)
Asserts that two longs are equal.
static void
assertEquals(java.lang.Object[] expecteds,
java.lang.Object[] actuals)
Deprecated.
use assertArrayEquals
static void
assertEquals(java.lang.Object expected,
java.lang.Object actual)
Asserts that two objects are equal.
static void
assertEquals(java.lang.String message,
double expected, double actual)
Deprecated.
Use
assertEquals(String message, double expected, double actual,
double epsilon)
instead
static void
assertEquals(java.lang.String message,
double expected, double actual,
double delta)
Asserts that two doubles or floats are equal to within a positive delta.
static void
assertEquals(java.lang.String message,
long expected, long actual)
Asserts that two longs are equal.
static void
assertEquals(java.lang.String message,
java.lang.Object[] expecteds,
java.lang.Object[] actuals)
Deprecated.
use assertArrayEquals
static void
assertEquals(java.lang.String message,
java.lang.Object expected,
java.lang.Object actual)
Asserts that two objects are equal.
static void
assertFalse(boolean condition)
Asserts that a condition is false.
static void
assertFalse(java.lang.String message,
boolean condition)
Asserts that a condition is false.
static void
assertNotNull(java.lang.Object object)
Asserts that an object isn't null.
static void
assertNotNull(java.lang.String message,
java.lang.Object object)
Asserts that an object isn't null.
static void
assertNotSame(java.lang.Object unexpected,
java.lang.Object actual)
Asserts that two objects do not refer to the same object.
static void
assertNotSame(java.lang.String message,
java.lang.Object unexpected,
java.lang.Object actual)
Asserts that two objects do not refer to the same object.
static void
assertNull(java.lang.Object object)
Asserts that an object is null.
static void
assertNull(java.lang.String message,
java.lang.Object object)
Asserts that an object is null.
static void
assertSame(java.lang.Object expected,
java.lang.Object actual)
Asserts that two objects refer to the same object.
static void
assertSame(java.lang.String message,
java.lang.Object expected,
java.lang.Object actual)
http://junit.sourceforge.net/javadoc/org/junit/Assert.html#assertFalse(java.lang.String, boolean)
2/12
7.12.2018
Assert (JUnit API)
Asserts that two objects refer to the same object.
static
assertThat(java.lang.String reason,
T actual, org.hamcrest.Matcher<T> matcher)
<T> void
Asserts that
actual
satisfies the condition specified by
matcher
.
Asserts that
actual
satisfies the condition specified by
matcher
.
Asserts that a condition is true.
static
assertThat(T actual,
org.hamcrest.Matcher<T> matcher)
<T> void
static void
assertTrue(boolean condition)
static void
assertTrue(java.lang.String message,
boolean condition)
Asserts that a condition is true.
static void
fail()
Fails a test with no message.
static void
fail(java.lang.String message)
Fails a test with the given message.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail
Assert
protected
Assert()
Protect constructor since it is a static only class
Method Detail
assertTrue
public static void
assertTrue(java.lang.String message,
boolean condition)
Asserts that a condition is true. If it isn't it throws an
AssertionError
with the given message.
Parameters:
message
- the identifying message for
condition
- condition to be checked
the
AssertionError
(
null
okay)
assertTrue
public static void
assertTrue(boolean condition)
Asserts that a condition is true. If it isn't it throws an
AssertionError
without a message.
Parameters:
condition
- condition to be checked
assertFalse
public static void
assertFalse(java.lang.String message,
boolean condition)
http://junit.sourceforge.net/javadoc/org/junit/Assert.html#assertFalse(java.lang.String, boolean)
3/12
7.12.2018
Assert (JUnit API)
Asserts that a condition is false. If it isn't it throws an
AssertionError
with the given message.
Parameters:
message
- the identifying message for
condition
- condition to be checked
the
AssertionError
(
null
okay)
assertFalse
public static void
assertFalse(boolean condition)
Asserts that a condition is false. If it isn't it throws an
AssertionError
without a message.
Parameters:
condition
- condition to be checked
fail
public static void
fail(java.lang.String message)
Fails a test with the given message.
Parameters:
message
- the identifying message for the
AssertionError
(
null
okay)
See Also:
AssertionError
fail
public static void
fail()
Fails a test with no message.
assertEquals
public static void
assertEquals(java.lang.String message,
java.lang.Object expected,
java.lang.Object actual)
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.
Parameters:
message
- the identifying message
expected
- expected value
actual
- actual value
for the
AssertionError
(
null
okay)
assertEquals
public static void
assertEquals(java.lang.Object expected,
java.lang.Object actual)
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.
Parameters:
http://junit.sourceforge.net/javadoc/org/junit/Assert.html#assertFalse(java.lang.String, boolean)
4/12
7.12.2018
Assert (JUnit API)
expected
- expected value
actual
- the value to check
against
expected
assertArrayEquals
public static void
assertArrayEquals(java.lang.String message,
java.lang.Object[] expecteds,
java.lang.Object[] actuals)
throws org.junit.internal.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.
Parameters:
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
Throws:
org.junit.internal.ArrayComparisonFailure
assertArrayEquals
public static void
assertArrayEquals(java.lang.Object[] expecteds,
java.lang.Object[] actuals)
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.
Parameters:
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
assertArrayEquals
public static void
assertArrayEquals(java.lang.String message,
byte[] expecteds,
byte[] actuals)
throws org.junit.internal.ArrayComparisonFailure
Asserts that two byte arrays are equal. If they are not, an
AssertionError
is thrown with the given
message.
Parameters:
message
- the identifying message for the
AssertionError
(
null
expecteds
- byte array with expected values.
actuals
- byte array with actual values
okay)
Throws:
org.junit.internal.ArrayComparisonFailure
assertArrayEquals
public static void
assertArrayEquals(byte[] expecteds,
byte[] actuals)
Asserts that two byte arrays are equal. If they are not, an
AssertionError
is thrown.
Parameters:
http://junit.sourceforge.net/javadoc/org/junit/Assert.html#assertFalse(java.lang.String, boolean)
5/12
Zgłoś jeśli naruszono regulamin