18. Unit Testing


This chapter focuses on testing with JUnit, one of the primary testing frameworks for Java. In its earliest sections and exercises, you will learn to write a successful unit test with JUnit to test your code, using assertions to verify that your code is correct. You will then be introduced to parameterized tests—a type of unit test which allows you to run the same test on a set of data inputs—which you will also learn to write. Finally, the chapter will define mocking, which is the technique whereby you will practice how to 'mock out' external dependencies so that you can concentrate on testing a single Java class.


Testing allows you to make sure your Java code performs correctly. For example, if ...

Get The Java Workshop now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.