0
0
JUnittesting~10 mins

Mockito dependency setup in JUnit - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add the Mockito dependency in Maven's <dependencies> section.

JUnit
<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-core</artifactId>
    <version>[1]</version>
    <scope>test</scope>
</dependency>
Drag options to blanks, or click blank then click option'
A3.12.4
B4.11.0
C2.23.4
D5.0.0
Attempts:
3 left
💡 Hint
Common Mistakes
Using an outdated or too new version that might not be compatible with your JUnit version.
2fill in blank
medium

Complete the Gradle dependency line to include Mockito for testing.

JUnit
testImplementation '[1]:mockito-core:3.12.4'
Drag options to blanks, or click blank then click option'
Amockito
Borg.junit.jupiter
Cjunit
Dorg.mockito
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'junit' or 'mockito' alone as group ID, which is incorrect.
3fill in blank
hard

Fix the error in the Mockito annotation import statement.

JUnit
import org.mockito.[1];
Drag options to blanks, or click blank then click option'
AMock
Bmock
CMocks
Dmockito
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'mock' which does not exist as an annotation.
4fill in blank
hard

Fill both blanks to initialize Mockito annotations in a JUnit 4 test class.

JUnit
@Before
public void setup() {
    Mockito.[1](this);
    // other setup code
}
Drag options to blanks, or click blank then click option'
AAnnotations
BinitMocks
Cinitialize
DsetupMocks
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'Annotations' or 'initialize'.
5fill in blank
hard

Fill all three blanks to use MockitoExtension with JUnit 5.

JUnit
@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
    }
}
Drag options to blanks, or click blank then click option'
AMockitoExtension
BopenMocks
C"mocked response"
DinitMocks
Attempts:
3 left
💡 Hint
Common Mistakes
Using initMocks instead of openMocks in JUnit 5.
Not providing a valid return value in when().