Blog Archives

01: Mockito interview Q&As & examples on @Mock, @Spy, @Captor and @InjectMocks

Firstly, you need the pom.xml entry to bring in the Mockito library.

@InjectMocks

Firstly, annotate the Test class with @RunWith(MockitoJUnitRunner.class) as shown below. The @InjectMocks annotation creates an instance of the class and injects the mocks that are created with the @Mock (or @Spy) annotations into this instance.… Read more ...



02: Mockito interview Q&As & examples on @Spy

A spy in mockito is a partial mock where part of the object will be mocked and part will use real method invocations. You can create a Spy a number of different ways. Consider using mocks instead of spies wherever possible as having to use a Spy could indicate violating…

Read more ...


03: Mockito interview Q&As & examples on @Mock, Mockito.mock(…) and @MockBean

Unlike a @Spy where you are spying on a real object, when you mock, you are creating a complete mock or fake object. Q: What are the different ways to mock an object? A: There are 3 ways to mock a dependent class that is sed by the class under…

Read more ...


04: Mockito interview Q&As & examples – PowerMock for mocking private & static methods

Let’s look at step by step to understand how to mock private & static methods with PowerMock & JUnit. pom.xml Step 1: The pom.xml file should have Mockito & Powermock libraries.

Read more ...


500+ Enterprise & Core Java programmer & architect Q&As

Java & Big Data Tutorials

Top