O'Reilly logo

Mastering Software Testing with JUnit 5 by Boni García

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required