Java Reference
In-Depth Information
Figure 12-1. JUnit lifecycle
As Figure 12-1 shows, JUnit executes those three methods in sequence for each method identified
with the @Test annotation until all the test methods in the test case have been executed. Listing 12-2
shows an example test case using all three of the discussed annotations.
Listing 12-2. Test of Foo
package com.apress.springbatch.chapter12;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class FooTest {
private Foo fooInstance;
public void setUp() {
fooInstance = new Foo();
public void testBar() {
String results =;
assertNotNull("Results were null", results);
assertEquals("The test was not a success", "success", results);
public void tearDown() {
Search WWH ::

Custom Search