Tests
Let’s focus now on the JUnit 5 tests of this application. We implement three types of tests: unit, integration, and end to end. As introduced before, for the unit test, we use Mockito to exercise the SUT in isolation. We decide to unit test the two major components of our application (CatService and CookiesServices) using Java classes containing different JUnit 5 tests.
Consider the first test (called RateCatsTest). As can be seen the code, in this class we are defining the class CatService as the SUT (using the annotation @InjectMocks) and the class CatRepository (which is used by CatService with dependency injection) as the DOC (using the annotation @Mock). The first test of this class (testCorrectRangeOfStars) is an example of parameterized ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access