assertXXX( ) Methods
Problem
You want to
use
the various assertXXX( ) methods to test different
conditions.
Solution
junit.framework.TestCase, the base class for all
test cases, extends from junit.framework.Assert,
which defines numerous overloaded assertXXX( )
methods. Your tests function by calling these methods.
Discussion
Table 4-1 summarizes the various
assertXXX( ) methods that can be found in
junit.framework.Assert. Although you could get by
with using assertTrue( ) for nearly every test,
using one of the more specific assertXXX( )
methods often makes your tests more understandable and provides good
failure messages. This table is only a summary; each of the methods
is overloaded as described shortly.
Table 4-1. Assert method summary
|
Method |
Description |
|---|---|
|
|
This was deprecated in JUnit 3.7 because it interferes with the J2SE
1.4 |
|
|
Compares two values for equality. The test passes if the values are equal. |
|
|
Evaluates a boolean expression. The test passes if the expression is
|
|
|
Compares an object reference to |
|
|
Compares the memory address of two object references using the
|
|
|
Compares an object reference to |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access