Test Spring-Boot Repository interface methods without touching the database using Mockito
"Mock" your repository method calls. Also, use @InjectMocks
instead @Autowired
for TransactionService
. And you can also use MockitoJUnitRunner
.
How to mock repository calls:
when(customerRepository.save(sender)).thenReturn(someSenderInstance);
To verify that mocked method call has been invoked use:
verify(customerRepository, times(1)).save(sender);
Also, remember one thing: You are testing services! Therefore, all calls to database should be mocked.