Complete the code to add the Mockito dependency in Maven's <dependencies> section.
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>[1]</version>
<scope>test</scope>
</dependency>A stable Mockito version for JUnit testing is 3.12.4. Using this version ensures compatibility and stability.
Complete the Gradle dependency line to include Mockito for testing.
testImplementation '[1]:mockito-core:3.12.4'
The group ID for Mockito in Gradle is 'org.mockito'. This is required to fetch the correct library.
Fix the error in the Mockito annotation import statement.
import org.mockito.[1];
The correct annotation to create mock objects is '@Mock' with capital 'M'. The import must be 'org.mockito.Mock'.
Fill both blanks to initialize Mockito annotations in a JUnit 4 test class.
@Before
public void setup() {
Mockito.[1](this);
// other setup code
}In JUnit 4, Mockito annotations are initialized by calling Mockito.initMocks(this) inside a method annotated with @Before.
Fill all three blanks to use MockitoExtension with JUnit 5.
@ExtendWith([1].class) public class MyTest { @Mock private Service service; @BeforeEach void init() { MockitoAnnotations.[2](this); } @Test void testService() { when(service.call()).thenReturn([3]); // test code } }
JUnit 5 uses @ExtendWith(MockitoExtension.class) to enable Mockito. The method openMocks(this) initializes mocks. The when() method needs a return value, here a string "mocked response".