Junit4断言
Junit4断言API:
http://junit.org/javadoc/latest/index.html
| Constructor Summary | |
|---|---|
protected |
Assert() Protect constructor since it is a static only class |
| Method Summary | ||
|---|---|---|
static void |
assertArrayEquals(boolean[] expecteds, boolean[] actuals) Asserts that two boolean arrays are equal. |
|
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, boolean[] expecteds, boolean[] actuals) Asserts that two boolean 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 delta) instead |
|
static void |
assertEquals(double expected, double actual, double delta) Asserts that two doubles are equal to within a positive delta. |
|
static void |
assertEquals(float expected, float actual, float delta) Asserts that two 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 delta) instead |
|
static void |
assertEquals(String message, double expected, double actual, double delta) Asserts that two doubles are equal to within a positive delta. |
|
static void |
assertEquals(String message, float expected, float actual, float delta) Asserts that two 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 |
assertNotEquals(double unexpected, double actual, double delta) Asserts that two doubles are not equal to within a positive delta. |
|
static void |
assertNotEquals(float unexpected, float actual, float delta) Asserts that two floats are not equal to within a positive delta. |
|
static void |
assertNotEquals(long unexpected, long actual) Asserts that two longs are not equals. |
|
static void |
assertNotEquals(Object unexpected, Object actual) Asserts that two objects are not equals. |
|
static void |
assertNotEquals(String message, double unexpected, double actual, double delta) Asserts that two doubles are not equal to within a positive delta. |
|
static void |
assertNotEquals(String message, float unexpected, float actual, float delta) Asserts that two floats are not equal to within a positive delta. |
|
static void |
assertNotEquals(String message, long unexpected, long actual) Asserts that two longs are not equals. |
|
static void |
assertNotEquals(String message, Object unexpected, Object actual) Asserts that two objects are not equals. |
|
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
|
assertThat(String reason, T actual, Matcher<? super T> matcher) Asserts that actual satisfies the condition specified by matcher. |
|
static
|
assertThat(T actual, Matcher<? super 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. |
|
| 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(String message,
boolean condition)
- Asserts that a condition is true. If it isn't it throws an
AssertionErrorwith the given message. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)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
AssertionErrorwithout a message. -
- Parameters:
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
AssertionErrorwith the given message. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)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
AssertionErrorwithout a message. -
- Parameters:
condition- condition to be checked
fail
public static void fail(String message)
- Fails a test with the given message.
-
- Parameters:
message- the identifying message for theAssertionError(nullokay)- See Also:
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
AssertionErroris thrown with the given message. Ifexpectedandactualarenull, they are considered equal. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)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
AssertionErrorwithout a message is thrown. Ifexpectedandactualarenull, they are considered equal. -
- Parameters:
expected- expected valueactual- the value to check againstexpected
assertNotEquals
public static void assertNotEquals(String message,
Object unexpected,
Object actual)
- Asserts that two objects are not equals. If they are, an
AssertionErroris thrown with the given message. Ifunexpectedandactualarenull, they are considered equal. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)unexpected- unexpected value to checkactual- the value to check againstunexpected
assertNotEquals
public static void assertNotEquals(Object unexpected,
Object actual)
- Asserts that two objects are not equals. If they are, an
AssertionErrorwithout a message is thrown. Ifunexpectedandactualarenull, they are considered equal. -
- Parameters:
unexpected- unexpected value to checkactual- the value to check againstunexpected
assertNotEquals
public static void assertNotEquals(String message,
long unexpected,
long actual)
- Asserts that two longs are not equals. If they are, an
AssertionErroris thrown with the given message. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)unexpected- unexpected value to checkactual- the value to check againstunexpected
assertNotEquals
public static void assertNotEquals(long unexpected,
long actual)
- Asserts that two longs are not equals. If they are, an
AssertionErrorwithout a message is thrown. -
- Parameters:
unexpected- unexpected value to checkactual- the value to check againstunexpected
assertNotEquals
public static void assertNotEquals(String message,
double unexpected,
double actual,
double delta)
- Asserts that two doubles are not equal to within a positive delta. If they are, an
AssertionErroris thrown with the given message. If the unexpected value is infinity then the delta value is ignored. NaNs are considered equal:assertNotEquals(Double.NaN, Double.NaN, *)fails -
- Parameters:
message- the identifying message for theAssertionError(nullokay)unexpected- unexpected valueactual- the value to check againstunexpecteddelta- the maximum delta betweenunexpectedandactualfor which both numbers are still considered equal.
assertNotEquals
public static void assertNotEquals(double unexpected,
double actual,
double delta)
- Asserts that two doubles are not equal to within a positive delta. If they are, an
AssertionErroris thrown. If the unexpected value is infinity then the delta value is ignored.NaNs are considered equal:assertNotEquals(Double.NaN, Double.NaN, *)fails -
- Parameters:
unexpected- unexpected valueactual- the value to check againstunexpecteddelta- the maximum delta betweenunexpectedandactualfor which both numbers are still considered equal.
assertNotEquals
public static void assertNotEquals(float unexpected,
float actual,
float delta)
- Asserts that two floats are not equal to within a positive delta. If they are, an
AssertionErroris thrown. If the unexpected value is infinity then the delta value is ignored.NaNs are considered equal:assertNotEquals(Float.NaN, Float.NaN, *)fails -
- Parameters:
unexpected- unexpected valueactual- the value to check againstunexpecteddelta- the maximum delta betweenunexpectedandactualfor which both numbers are still considered equal.
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
AssertionErroris thrown with the given message. Ifexpectedsandactualsarenull, they are considered equal. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)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(Object[] expecteds,
Object[] actuals)
- Asserts that two object arrays are equal. If they are not, an
AssertionErroris thrown. Ifexpectedandactualarenull, they are considered equal. -
- Parameters:
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,
boolean[] expecteds,
boolean[] actuals)
throws org.junit.internal.ArrayComparisonFailure
- Asserts that two boolean arrays are equal. If they are not, an
AssertionErroris thrown with the given message. Ifexpectedsandactualsarenull, they are considered equal. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)expecteds- boolean array with expected values.actuals- boolean array with expected values.- Throws:
org.junit.internal.ArrayComparisonFailure
assertArrayEquals
public static void assertArrayEquals(boolean[] expecteds,
boolean[] actuals)
- Asserts that two boolean arrays are equal. If they are not, an
AssertionErroris thrown. Ifexpectedandactualarenull, they are considered equal. -
- Parameters:
expecteds- boolean array with expected values.actuals- boolean array with expected 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
AssertionErroris thrown with the given message. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)expecteds- byte array with expected values.actuals- byte array with actual values- 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
AssertionErroris thrown. -
- Parameters:
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
AssertionErroris thrown with the given message. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)expecteds- char array with expected values.actuals- char array with actual values- Throws:
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
AssertionErroris thrown. -
- Parameters:
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
AssertionErroris thrown with the given message. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)expecteds- short array with expected values.actuals- short array with actual values- Throws:
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
AssertionErroris thrown. -
- Parameters:
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
AssertionErroris thrown with the given message. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)expecteds- int array with expected values.actuals- int array with actual values- Throws:
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
AssertionErroris thrown. -
- Parameters:
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
AssertionErroris thrown with the given message. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)expecteds- long array with expected values.actuals- long array with actual values- Throws:
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
AssertionErroris thrown. -
- Parameters:
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
AssertionErroris thrown with the given message. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)expecteds- double array with expected values.actuals- double array with actual valuesdelta- the maximum delta betweenexpecteds[i]andactuals[i]for which both numbers are still considered equal.- Throws:
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
AssertionErroris thrown. -
- Parameters:
expecteds- double array with expected values.actuals- double array with actual valuesdelta- the maximum delta betweenexpecteds[i]andactuals[i]for which both numbers are still considered equal.
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
AssertionErroris thrown with the given message. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)expecteds- float array with expected values.actuals- float array with actual valuesdelta- the maximum delta betweenexpecteds[i]andactuals[i]for which both numbers are still considered equal.- Throws:
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
AssertionErroris thrown. -
- Parameters:
expecteds- float array with expected values.actuals- float array with actual valuesdelta- the maximum delta betweenexpecteds[i]andactuals[i]for which both numbers are still considered equal.
assertEquals
public static void assertEquals(String message,
double expected,
double actual,
double delta)
- Asserts that two doubles are equal to within a positive delta. If they are not, an
AssertionErroris 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 -
- Parameters:
message- the identifying message for theAssertionError(nullokay)expected- expected valueactual- the value to check againstexpecteddelta- the maximum delta betweenexpectedandactualfor which both numbers are still considered equal.
assertEquals
public static void assertEquals(String message,
float expected,
float actual,
float delta)
- Asserts that two floats are equal to within a positive delta. If they are not, an
AssertionErroris thrown with the given message. If the expected value is infinity then the delta value is ignored. NaNs are considered equal:assertEquals(Float.NaN, Float.NaN, *)passes -
- Parameters:
message- the identifying message for theAssertionError(nullokay)expected- expected valueactual- the value to check againstexpecteddelta- the maximum delta betweenexpectedandactualfor which both numbers are still considered equal.
assertNotEquals
public static void assertNotEquals(String message,
float unexpected,
float actual,
float delta)
- Asserts that two floats are not equal to within a positive delta. If they are, an
AssertionErroris thrown with the given message. If the unexpected value is infinity then the delta value is ignored. NaNs are considered equal:assertNotEquals(Float.NaN, Float.NaN, *)fails -
- Parameters:
message- the identifying message for theAssertionError(nullokay)unexpected- unexpected valueactual- the value to check againstunexpecteddelta- the maximum delta betweenunexpectedandactualfor 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
AssertionErroris thrown. -
- Parameters:
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
AssertionErroris thrown with the given message. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)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 delta)instead -
assertEquals
@Deprecated
public static void assertEquals(String message,
double expected,
double actual)
- Deprecated. Use
assertEquals(String message, double expected, double actual, double delta)instead -
assertEquals
public static void assertEquals(double expected,
double actual,
double delta)
- Asserts that two doubles are equal to within a positive delta. If they are not, an
AssertionErroris thrown. If the expected value is infinity then the delta value is ignored.NaNs are considered equal:assertEquals(Double.NaN, Double.NaN, *)passes -
- Parameters:
expected- expected valueactual- the value to check againstexpecteddelta- the maximum delta betweenexpectedandactualfor which both numbers are still considered equal.
assertEquals
public static void assertEquals(float expected,
float actual,
float delta)
- Asserts that two floats are equal to within a positive delta. If they are not, an
AssertionErroris thrown. If the expected value is infinity then the delta value is ignored. NaNs are considered equal:assertEquals(Float.NaN, Float.NaN, *)passes -
- Parameters:
expected- expected valueactual- the value to check againstexpecteddelta- the maximum delta betweenexpectedandactualfor 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
AssertionErroris thrown with the given message. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)object- Object to check ornull
assertNotNull
public static void assertNotNull(Object object)
- Asserts that an object isn't null. If it is an
AssertionErroris thrown. -
- Parameters:
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
AssertionErroris thrown with the given message. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)object- Object to check ornull
assertNull
public static void assertNull(Object object)
- Asserts that an object is null. If it isn't an
AssertionErroris thrown. -
- Parameters:
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
AssertionErroris thrown with the given message. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)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
AssertionErrorwithout a message is thrown. -
- Parameters:
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
AssertionErroris thrown with the given message. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)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
AssertionErrorwithout a message is thrown. -
- Parameters:
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
AssertionErroris thrown with the given message. Ifexpectedsandactualsarenull, they are considered equal. -
- Parameters:
message- the identifying message for theAssertionError(nullokay)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
AssertionErroris thrown. Ifexpectedandactualarenull, they are considered equal. -
- Parameters:
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,
Matcher<? super T> matcher)
- Asserts that
actualsatisfies the condition specified bymatcher. If not, anAssertionErroris 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))) // passesorg.hamcrest.Matcherdoes not currently document the meaning of its type parameterT. This method assumes that a matcher typed asMatcher<T>can be meaningfully applied only to values that could be assigned to a variable of typeT. -
- Type Parameters:
T- the static type accepted by the matcher (this can flag obvious compile-time problems such asassertThat(1, is("a"))- Parameters:
actual- the computed value being comparedmatcher- an expression, built ofMatchers, specifying allowed values- See Also:
CoreMatchers,MatcherAssert
assertThat
public static <T> void assertThat(String reason,
T actual,
Matcher<? super T> matcher)
- Asserts that
actualsatisfies the condition specified bymatcher. If not, anAssertionErroris 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))) // passesorg.hamcrest.Matcherdoes not currently document the meaning of its type parameterT. This method assumes that a matcher typed asMatcher<T>can be meaningfully applied only to values that could be assigned to a variable of typeT. -
- Type Parameters:
T- the static type accepted by the matcher (this can flag obvious compile-time problems such asassertThat(1, is("a"))- Parameters:
reason- additional information about the erroractual- the computed value being comparedmatcher- an expression, built ofMatchers, specifying allowed values- See Also:
CoreMatchers,MatcherAssert
Junit4断言的更多相关文章
- 【单元测试】Junit 4(三)--Junit4断言
1.0 前言 断言(assertion)是一种在程序中的一阶逻辑(如:一个结果为真或假的逻辑判断式),目的为了表示与验证软件开发者预期的结果--当程序执行到断言的位置时,对应的断言应该为真.若断言 ...
- Junit4 断言新方法
话不多少说,直接上代码 package ASSERTTEST; import org.junit.Assert; import org.hamcrest.*;import org.junit.Test ...
- 5月3日上课笔记-properties文件,junit测试,mvc封层等
StringBuffer 线程安全,效率低 StringBuilder 线程不安全,效率高 判断数组是null还是空数组 null 空数组 int[] array=null; int[] array2 ...
- Junit4中的新断言assertThat的使用方法
如果需要是用assertThat需要在项目中引入junit4的jar包.(匹配器和断言方法在junit4的jar包中都能找到,引入就可以了) 下面是常用断言的代码 1 import static or ...
- SpringBoot JUnit4的断言和注解
Junit4的断言常用方法: assertArrayEquals( new Object[]{ studentService.likeName("小明2").size() > ...
- Junit3断言
在Robotium自动化测试的过程中,发现没有断言的脚本是没有意义的,现整理Junit3和Junit4的断言,供日后查阅. http://junit.org/ Junit3断言API: http:// ...
- Junit3与Junit4的区别
Junit4最大的亮点就是引入了注解(annotation),通过解析注解就可以为测试提供相应的信息,抛弃junit3使用命名约束以及反射机制的方法. /** * 被测试类 */ package co ...
- 利用Junit4进行程序模块的测试,回归测试
①在你的工程里导入JUnit4的包 ②右击创建JUnit测试类,在测试类中编写测试代码即可. JUnit 目前需要掌握的有一下几点: Fixture系列:BeforeClass,AfterClass, ...
- Java魔法堂:JUnit4使用详解
目录 1. 开 ...
随机推荐
- java 枚举类型 构造函数及用法
// 1. 定义枚举类型 public enum Light { // 利用构造函数传参 RED (1), GREEN (3), YELLOW (2); // 定义私有变量 private int n ...
- Java学习
第一个java程序: 用记事本创建一个文件名为HelloWorld.java文件,我的目录为D:\My Documents\Java-workspace\Test\HelloWorld.java. 打 ...
- warning 4510 with const member in struct
I write a code section as this struct My{const int a;}; OK, then set the warning level then I will g ...
- javascript知识点之DOM与window对象
在学习javascript过程中只是一知半解好多,碰到自己不知道属性方法,到最后都不知道自己学到了什么 js代码为什么这样写 为什么你知道这方法或属性可以这样用. DOM和window对象 DOM基本 ...
- CSS布局奇技淫巧:各种居中
居中是我们使用css来布局时常遇到的情况.使用css来进行居中时,有时一个属性就能搞定,有时则需要一定的技巧才能兼容到所有浏览器,本文就居中的一些常用方法做个简单的介绍. 注:本文所讲方法除了特别说明 ...
- C 语言中的优先级
先看一段代码: /********************************************************************* * @fn bdAddr2Str * * ...
- 使用 Fluent API 配置/映射属性和类型(摘自微软Data Access and Storage)
使用 Fluent API 配置/映射属性和类型 使用实体框架 Code First 时,默认行为是使用一组 EF 中内嵌的约定将 POCO 类映射到表.但是,有时您无法或不想遵守这些约定,需要将实体 ...
- [原创]cocos2d-x研习录-第三阶 特性之粒子系统
我想接触过游戏引擎的同学,对粒子系统应该不会陌生.它用于解决由大量按一定规则运动(变化)的微小物质在计算机上的生成和显示问题.粒子系统在游戏中有着非常广泛的应用,可以模拟很多现象,如火花.爆炸.烟雾. ...
- RestEasy 3.x 系列之四:使用Hibernate_Validator进行数据校验
使用Hibernate_Validator进行数据校验,好处不言而喻:规范统一,低耦合度. 1.pom.xml <dependency> <groupId>org.hibern ...
- MYCAT介绍(转)
从定义和分类来看,它是一个开源的分布式数据库系统,是一个实现了MySQL协议的服务器,前端用户可以把它看作是一个数据库代理,用MySQL客户端工具和命令行访问,而其后端可以用MySQL原生协议与多个M ...