Unit Testing with Mockito and JUnit5
Let's explore unit testing using the Mockito and JUnit5 framework.
We'll cover the following...
We'll cover the following...
TodoTypeServiceTest
Let’s start with unit testing TodoTypeService
. We’ll create the TodoTypeServiceTest
in the io.educative.unit
package under the src/test/java
directory.
Press + to interact
package io.educative.unit;import io.educative.repositories.TodoTypeRepository;import io.educative.services.TodoTypeService;import org.mockito.Mockito;import javax.validation.Validator;public class TodoTypeServiceTest {private TodoTypeRepository todoTypeRepository = Mockito.mock(TodoTypeRepository.class);private Validator validator = Mockito.mock(Validator.class);private TodoTypeService service = new TodoTypeService(todoTypeRepository, validator);}
We’ve used the Mockito
class from the Mockito framework to mock the TodoTypeRepository
and Validator
classes required to create the instance of the TodoTypeService
class.
Now, we can add a simple unit test named ...