Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

1. JUnit Pocket Guide > JUnit’s Implementation

JUnit’s Implementation

JUnit’s implementation is a bit unusual, using techniques that are difficult to maintain in ordinary application code. Knowing a bit about the implementation can help as you write tests.

Consider a test case class with two test methods in it:

public class EmptyTest extends TestCase {
    List empty= new ArrayList(  );

    public void testSize(  ) {
        assertEquals(0, empty.size(  ));
    }

    public void testIsEmpty(  ) {
        assertTrue(empty.isEmpty(  ));
    }
}

When the test is run, the first thing JUnit does is convert the test class into a Test object: in this case a TestSuite containing two instances of EmptyTest, as shown in Figure 1-2.

Tests about to be run
Figure 1-2. Tests about to be run

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint