|
|||||||||
上一个类 下一个类 | 框架 无框架 | ||||||||
摘要: 嵌套 | 字段 | 构造器 | 方法 | 详细信息: 字段 | 构造器 | 方法 |
org.junit Class Assert
java.lang.Object org.junit.Assert
public class Assert
- extends 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(...);
- 另请参见:
AssertionError
构造器摘要 | |
---|---|
protected |
Assert()
Protect constructor since it is a static only class |
方法摘要 | |
---|---|
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(double[] expecteds,
double[] actuals,
double delta)
Asserts that two double arrays are equal. |
static void |
assertArrayEquals(float[] expecteds,
float[] actuals,
float delta)
Asserts that two float 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(Object[] expecteds,
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(String message,
byte[] expecteds,
byte[] actuals)
Asserts that two byte arrays are equal. |
static void |
assertArrayEquals(String message,
char[] expecteds,
char[] actuals)
Asserts that two char arrays are equal. |
static void |
assertArrayEquals(String message,
double[] expecteds,
double[] actuals,
double delta)
Asserts that two double arrays are equal. |
static void |
assertArrayEquals(String message,
float[] expecteds,
float[] actuals,
float delta)
Asserts that two float arrays are equal. |
static void |
assertArrayEquals(String message,
int[] expecteds,
int[] actuals)
Asserts that two int arrays are equal. |
static void |
assertArrayEquals(String message,
long[] expecteds,
long[] actuals)
Asserts that two long arrays are equal. |
static void |
assertArrayEquals(String message,
Object[] expecteds,
Object[] actuals)
Asserts that two object arrays are equal. |
static void |
assertArrayEquals(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(Object[] expecteds,
Object[] actuals)
Deprecated. use assertArrayEquals |
static void |
assertEquals(Object expected,
Object actual)
Asserts that two objects are equal. |
static void |
assertEquals(String message,
double expected,
double actual)
Deprecated. Use assertEquals(String message, double expected, double actual, double epsilon)
instead |
static void |
assertEquals(String message,
double expected,
double actual,
double delta)
Asserts that two doubles or floats are equal to within a positive delta. |
static void |
assertEquals(String message,
long expected,
long actual)
Asserts that two longs are equal. |
static void |
assertEquals(String message,
Object[] expecteds,
Object[] actuals)
Deprecated. use assertArrayEquals |
static void |
assertEquals(String message,
Object expected,
Object actual)
Asserts that two objects are equal. |
static void |
assertFalse(boolean condition)
Asserts that a condition is false. |
static void |
assertFalse(String message,
boolean condition)
Asserts that a condition is false. |
static void |
assertNotNull(Object object)
Asserts that an object isn't null. |
static void |
assertNotNull(String message,
Object object)
Asserts that an object isn't null. |
static void |
assertNotSame(Object unexpected,
Object actual)
Asserts that two objects do not refer to the same object. |
static void |
assertNotSame(String message,
Object unexpected,
Object actual)
Asserts that two objects do not refer to the same object. |
static void |
assertNull(Object object)
Asserts that an object is null. |
static void |
assertNull(String message,
Object object)
Asserts that an object is null. |
static void |
assertSame(Object expected,
Object actual)
Asserts that two objects refer to the same object. |
static void |
assertSame(String message,
Object expected,
Object actual)
Asserts that two objects refer to the same object. |
static
<T> void |
assertThat(String reason,
T actual,
org.hamcrest.Matcher<T> matcher)
Asserts that
actual
satisfies the condition specified by
matcher
.static
<T> void
assertThat(T actual,
org.hamcrest.Matcher<T> matcher)
Asserts that
actual
satisfies the condition specified by
matcher
.static void
assertTrue(boolean condition)
Asserts that a condition is true.
static void
assertTrue(String message,
boolean condition)
Asserts that a condition is true.
static void
fail()
Fails a test with no message.
static void
fail(String message)
Fails a test with the given message.
类方法继承: java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
构造器详细信息 |
---|
Assert
protected Assert()
- Protect constructor since it is a static only class
方法详细信息 |
---|
assertTrue
public static void assertTrue(String message, boolean condition)
- Asserts that a condition is true. If it isn't it throws an
AssertionError
with the given message. - 参数:
message
- the identifying message for theAssertionError
(null
okay)condition
- condition to be checked
assertTrue
public static void assertTrue(boolean condition)
- Asserts that a condition is true. If it isn't it throws an
AssertionError
without a message. - 参数:
condition
- condition to be checked
assertFalse
public static void assertFalse(String message, boolean condition)
- Asserts that a condition is false. If it isn't it throws an
AssertionError
with the given message. - 参数:
message
- the identifying message for theAssertionError
(null
okay)condition
- condition to be checked
assertFalse
public static void assertFalse(boolean condition)
- Asserts that a condition is false. If it isn't it throws an
AssertionError
without a message. - 参数:
condition
- condition to be checked
fail
public static void fail(String message)
- Fails a test with the given message.
- 参数:
message
- the identifying message for theAssertionError
(null
okay)- 另请参见:
AssertionError
fail
public static void fail()
- Fails a test with no message.
assertEquals
public static void assertEquals(String message, Object expected, Object actual)
- Asserts that two objects are equal. If they are not, an
AssertionError
is thrown with the given message. Ifexpected
andactual
arenull
, they are considered equal. - 参数:
message
- the identifying message for theAssertionError
(null
okay)expected
- expected valueactual
- actual value
assertEquals
public static void assertEquals(Object expected, Object actual)
- Asserts that two objects are equal. If they are not, an
AssertionError
without a message is thrown. Ifexpected
andactual
arenull
, they are considered equal. - 参数:
expected
- expected valueactual
- the value to check againstexpected
assertArrayEquals
public static void assertArrayEquals(String message, Object[] expecteds, 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. Ifexpecteds
andactuals
arenull
, they are considered equal. - 参数:
message
- the identifying message for theAssertionError
(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- 抛出异常:
org.junit.internal.ArrayComparisonFailure
assertArrayEquals
public static void assertArrayEquals(Object[] expecteds, Object[] actuals)
- Asserts that two object arrays are equal. If they are not, an
AssertionError
is thrown. Ifexpected
andactual
arenull
, they are considered equal. - 参数:
expecteds
- Object array or array of arrays (multi-dimensional array) with expected valuesactuals
- Object array or array of arrays (multi-dimensional array) with actual values
assertArrayEquals
public static void assertArrayEquals(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. - 参数:
message
- the identifying message for theAssertionError
(null
okay)expecteds
- byte array with expected values.actuals
- byte array with actual values- 抛出异常:
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. - 参数:
expecteds
- byte array with expected values.actuals
- byte array with actual values
assertArrayEquals
public static void assertArrayEquals(String message, char[] expecteds, char[] actuals) throws org.junit.internal.ArrayComparisonFailure
- Asserts that two char arrays are equal. If they are not, an
AssertionError
is thrown with the given message. - 参数:
message
- the identifying message for theAssertionError
(null
okay)expecteds
- char array with expected values.actuals
- char array with actual values- 抛出异常:
org.junit.internal.ArrayComparisonFailure
assertArrayEquals
public static void assertArrayEquals(char[] expecteds, char[] actuals)
- 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
assertArrayEquals
public static void assertArrayEquals(String message, short[] expecteds, short[] actuals) throws org.junit.internal.ArrayComparisonFailure
- Asserts that two short arrays are equal. If they are not, an
AssertionError
is thrown with the given message. - 参数:
message
- the identifying message for theAssertionError
(null
okay)expecteds
- short array with expected values.actuals
- short array with actual values- 抛出异常:
org.junit.internal.ArrayComparisonFailure
assertArrayEquals
public static void assertArrayEquals(short[] expecteds, short[] actuals)
- 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
assertArrayEquals
public static void assertArrayEquals(String message, int[] expecteds, int[] actuals) throws org.junit.internal.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 theAssertionError
(null
okay)expecteds
- int array with expected values.actuals
- int array with actual values- 抛出异常:
org.junit.internal.ArrayComparisonFailure
assertArrayEquals
public static void assertArrayEquals(int[] expecteds, int[] actuals)
- 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
assertArrayEquals
public static void assertArrayEquals(String message, long[] expecteds, long[] actuals) throws org.junit.internal.ArrayComparisonFailure
- Asserts that two long arrays are equal. If they are not, an
AssertionError
is thrown with the given message. - 参数:
message
- the identifying message for theAssertionError
(null
okay)expecteds
- long array with expected values.actuals
- long array with actual values- 抛出异常:
org.junit.internal.ArrayComparisonFailure
assertArrayEquals
public static void assertArrayEquals(long[] expecteds, long[] actuals)
- 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
assertArrayEquals
public static void assertArrayEquals(String message, double[] expecteds, double[] actuals, double delta) throws org.junit.internal.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 theAssertionError
(null
okay)expecteds
- double array with expected values.actuals
- double array with actual values- 抛出异常:
org.junit.internal.ArrayComparisonFailure
assertArrayEquals
public static void assertArrayEquals(double[] expecteds, double[] actuals, double delta)
- 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
assertArrayEquals
public static void assertArrayEquals(String message, float[] expecteds, float[] actuals, float delta) throws org.junit.internal.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 theAssertionError
(null
okay)expecteds
- float array with expected values.actuals
- float array with actual values- 抛出异常:
org.junit.internal.ArrayComparisonFailure
assertArrayEquals
public static void assertArrayEquals(float[] expecteds, float[] actuals, float delta)
- 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
assertEquals
public static void assertEquals(String message, double expected, double actual, double delta)
- 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 theAssertionError
(null
okay)expected
- expected valueactual
- the value to check againstexpected
delta
- the maximum delta betweenexpected
andactual
for which both numbers are still considered equal.
assertEquals
public static void assertEquals(long expected, long actual)
- Asserts that two longs are equal. If they are not, an
AssertionError
is thrown. - 参数:
expected
- expected long value.actual
- actual long value
assertEquals
public static void assertEquals(String message, long expected, long actual)
- Asserts that two longs are equal. If they are not, an
AssertionError
is thrown with the given message. - 参数:
message
- the identifying message for theAssertionError
(null
okay)expected
- long expected value.actual
- long actual value
assertEquals
@Deprecated
public static void assertEquals(double expected,
double actual)
- Deprecated. Use
assertEquals(double expected, double actual, double epsilon)
instead
assertEquals
@Deprecated public static void assertEquals(String message, double expected, double actual)
- Deprecated. Use
assertEquals(String message, double expected, double actual, double epsilon)
instead
assertEquals
public static void assertEquals(double expected, double actual, double delta)
- 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 valueactual
- the value to check againstexpected
delta
- the maximum delta betweenexpected
andactual
for which both numbers are still considered equal.
assertNotNull
public static void assertNotNull(String message, Object object)
- Asserts that an object isn't null. If it is an
AssertionError
is thrown with the given message. - 参数:
message
- the identifying message for theAssertionError
(null
okay)object
- Object to check ornull
assertNotNull
public static void assertNotNull(Object object)
- Asserts that an object isn't null. If it is an
AssertionError
is thrown. - 参数:
object
- Object to check ornull
assertNull
public static void assertNull(String message, Object object)
- Asserts that an object is null. If it is not, an
AssertionError
is thrown with the given message. - 参数:
message
- the identifying message for theAssertionError
(null
okay)object
- Object to check ornull
assertNull
public static void assertNull(Object object)
- Asserts that an object is null. If it isn't an
AssertionError
is thrown. - 参数:
object
- Object to check ornull
assertSame
public static void assertSame(String message, Object expected, Object actual)
- 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 theAssertionError
(null
okay)expected
- the expected objectactual
- the object to compare toexpected
assertSame
public static void assertSame(Object expected, Object actual)
- 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 objectactual
- the object to compare toexpected
assertNotSame
public static void assertNotSame(String message, Object unexpected, Object actual)
- 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 theAssertionError
(null
okay)unexpected
- the object you don't expectactual
- the object to compare tounexpected
assertNotSame
public static void assertNotSame(Object unexpected, Object actual)
- 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 expectactual
- the object to compare tounexpected
assertEquals
@Deprecated public static void assertEquals(String message, Object[] expecteds, Object[] actuals)
- Deprecated. use assertArrayEquals
- Asserts that two object arrays are equal. If they are not, an
AssertionError
is thrown with the given message. Ifexpecteds
andactuals
arenull
, they are considered equal. - 参数:
message
- the identifying message for theAssertionError
(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
assertEquals
@Deprecated public static void assertEquals(Object[] expecteds, Object[] actuals)
- Deprecated. use assertArrayEquals
- Asserts that two object arrays are equal. If they are not, an
AssertionError
is thrown. Ifexpected
andactual
arenull
, they are considered equal. - 参数:
expecteds
- Object array or array of arrays (multi-dimensional array) with expected valuesactuals
- Object array or array of arrays (multi-dimensional array) with actual values
assertThat
public static <T> void assertThat(T actual, org.hamcrest.Matcher<T> matcher)
- Asserts that
actual
satisfies the condition specified bymatcher
. If not, anAssertionError
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
- Type Parameters:
T
- the static type accepted by the matcher (this can flag obvious compile-time problems such asassertThat(1, is("a"))
- 参数:
actual
- the computed value being comparedmatcher
- an expression, built ofMatcher
s, specifying allowed values- 另请参见:
CoreMatchers
,JUnitMatchers
assertThat
public static <T> void assertThat(String reason, T actual, org.hamcrest.Matcher<T> matcher)
- Asserts that
actual
satisfies the condition specified bymatcher
. If not, anAssertionError
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
- Type Parameters:
T
- the static type accepted by the matcher (this can flag obvious compile-time problems such asassertThat(1, is("a"))
- 参数:
reason
- additional information about the erroractual
- the computed value being comparedmatcher
- an expression, built ofMatcher
s, specifying allowed values- 另请参见:
CoreMatchers
,JUnitMatchers
|
|||||||||
上一个类 下一个类 | 框架 无框架 | ||||||||
摘要: 嵌套 | 字段 | 构造器 | 方法 | 详细信息: 字段 | 构造器 | 方法 |