Creating a unit test

Now, let's write a test for the multiplyByTwo() method of the SimpleMath class, because we would like to make sure that the multiplyByTwo() method works as expected. Such tests are useful as long as the project exists, because you can run them every time the code is changed, and verify that the existing functionality has not been changed accidentally.

A method is the smallest testable part of an application. That's why such a test is called a unit test. It is a good idea to have a unit test for each method that you create (except the trivial ones, such as getters and setters, for example). 

We will use a popular test framework called JUnit. There are several versions of it. At the time of this writing, version 5 is the ...

Get Introduction to Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.