Summary
This chapter introduced unit testing. Testing is good and you want to write tests for all your Java code. If you write successful tests, then you can feel confident your code was written correctly.
JUnit provides the most popular testing framework for writing Java unit tests, though there are other frameworks you can try as well. The @Test
annotation on a method tells JUnit that the given code is considered a test. JUnit will execute the test and see whether it succeeds. The JUnit assertions class contains a few static
methods that you can use to verify the test results.
A parameterized test is a test into which you pass a few parameters. This is very useful when writing tests for code that you want to ensure can handle a variety of inputs. Mocking is a technique where you mock out external dependencies so that a unit test can concentrate on testing just one class.