Java Reference
In-Depth Information
Table 2.1
JUnit assert method sample
assert XXX method
What it's used for
assertArrayEquals("message", A, B)
Asserts the equality of the A and B arrays.
assertEquals("message", A, B)
Asserts the equality of objects A and B . This
assert invokes the equals() method on the
first object against the second.
assertSame("message", A, B)
Asserts that the A and B objects are the same
object. Whereas the previous assert method
checks to see that A and B have the same
value (using the equals method), the
assertSame method checks to see if the A
and B objects are one and the same object
(using the == operator).
assertTrue("message", A)
Asserts that the A condition is true.
assertNotNull("message", A)
Asserts that the A object isn't null.
When you need to run several test classes at once, you create another object called a
test suite (or Suite .) Your test suite is a special test runner (or Runner ), so you can run
it as you would a test class. Once you understand how a test class, Suite , and Runner
work, you'll be able to write whatever tests you need. These three objects form the
backbone of the JU nit framework.
On a daily basis, you need only write test classes and test suites. The other classes
work behind the scenes to bring your tests to life.
DEFINITIONS Test class (or TestCase or test case) —A class that contains one or
more tests represented by methods annotated with @Test . Use a test class to
group together tests that exercise common behaviors. In the remainder of
this topic, when we mention a test , we mean a method annotated with @Test ;
when we mention a test case (or test class), we mean a class that holds these
test methods—a set of tests. There's usually a one-to-one mapping between a
production class and a test class.
Suite (or test suite) —A group of tests. A test suite is a convenient way to group
together tests that are related. For example, if you don't define a test suite for
a test class, JU nit automatically provides a test suite that includes all tests
found in the test class (more on that later). A suite usually groups test classes
from the same package.
Runner (or test runner) —A runner of test suites. JU nit provides various runners
to execute your tests. We cover these runners later in this chapter and show
you how to write your own test runners.
 
 
 
 
 
 
 
 
 
 
 
 
 
Search WWH ::




Custom Search