In this tutorial, we will understand how to use Mockito framework. We will understand and implement the below topics.
Part 1 – What is Mockito?
In this tutorial, we will understand below topics –
– What is a Mock Object?
– When should I mock?
– Mockito Framework
– Enable Mockito Annotations
– How to Mock Object with @Mock & @InjectMock annotations in Spring application?
https://www.onlyfullstack.com/what-is-mock-object-what-is-mockito/
Part 2 – How to mock methods with Mockito?
– How to mock methods?
1. when/then
2. when/thenThrow
3. when/thenAnswer
https://www.onlyfullstack.com/how-to-mock-methods-with-mockito/
1. when/then
2. when/thenThrow
3. when/thenAnswer
https://www.onlyfullstack.com/how-to-mock-methods-with-mockito/
Part 3- How to mock void methods with Mockito
– Mocking Void Methods
– Three ways to mock the void method:
1. doNothing/when
2. doAnswer/when
3. doThrow/when
https://www.onlyfullstack.com/how-to-mock-void-methods-with-mockito/
– Mocking Void Methods
– Three ways to mock the void method:
1. doNothing/when
2. doAnswer/when
3. doThrow/when
https://www.onlyfullstack.com/how-to-mock-void-methods-with-mockito/
Part 4 – How to verify mocks in Mockito
– Simple verify method
– Variations in verify method
– Verify with the number of times
– Mockito Verify Order of Invocation
https://www.onlyfullstack.com/how-to-verify-the-mocks-in-mockito/
– Simple verify method
– Variations in verify method
– Verify with the number of times
– Mockito Verify Order of Invocation
https://www.onlyfullstack.com/how-to-verify-the-mocks-in-mockito/
Part 5 – Mockito Mock vs Spy
– Mockito Mock vs Spy
1. Object declaration
2. When the methods are not mocked
3. When the method is mocked
https://onlyfullstack.blogspot.com/2019/02/mockito-mock-vs-spy.html
1. Object declaration
2. When the methods are not mocked
3. When the method is mocked
https://onlyfullstack.blogspot.com/2019/02/mockito-mock-vs-spy.html