Sobes.tech
Junior — Middle

What tool or library have you used for creating mock objects related to the @Mock annotation?

sobes.tech AI

Answer from AI

To create mock objects using the @Mock annotation, the most commonly used library is Mockito. It allows easy creation of dependency mocks for unit tests in Java.

Example usage:

import static org.mockito.Mockito.*;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

public class MyTest {
    @Mock
    private MyService myService;

    @Before
    public void init() {
        MockitoAnnotations.openMocks(this);
    }

    @Test
    public void testSomething() {
        when(myService.getData()).thenReturn("mocked data");
        // test code
    }
}
What tool or library have you used for creating mock… - sobes.tech