Mockito for beginners:
Mockito is an open source testing framework, and it is a widely used for junit testing with mocking beans/repositories in frameworks such as spring mvc & spring boot. The framework allows the creation of test double objects in automated unit tests for the purpose of test-driven development or behavior-driven development. The framework’s name and logo are a play on mojitos, a type of drink.
How to Mock void method ?
Note: deleteAll is a void method.
How to Mock public methods of a same class ?
NgDeveloper ngDeveloperSpy = Mockito.spy(new NgDeveloper()); when(ngDeveloperSpy.getAuthor()).thenReturn("Mirthbees");
Note: getAuthor() is the public method which we need to mock, so we have created a spy of a class then called getAuthor() method and mocked the response as “Mirthbees” using when and thenReturn.
1,076 total views, 2 views today