0
0
JUnittesting~5 mins

Mockito dependency setup in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is Mockito used for in testing?
Mockito is a Java library used to create mock objects for unit testing. It helps simulate behavior of real objects to test code in isolation.
Click to reveal answer
beginner
How do you add Mockito dependency using Maven?
Add this to your pom.xml inside <dependencies>:<br>
<dependency>
  <groupId>org.mockito</groupId>
  <artifactId>mockito-core</artifactId>
  <version>5.4.0</version>
  <scope>test</scope>
</dependency>
Click to reveal answer
beginner
How to add Mockito dependency using Gradle?
Add this line to your build.gradle inside dependencies:<br>
testImplementation 'org.mockito:mockito-core:5.4.0'
Click to reveal answer
intermediate
What JUnit version is commonly used with Mockito 5+?
JUnit 5 (JUnit Jupiter) is commonly used with Mockito 5 and above for modern testing features and better integration.
Click to reveal answer
intermediate
What is the purpose of the @ExtendWith(MockitoExtension.class) annotation?
It tells JUnit 5 to enable Mockito support, so you can use annotations like @Mock and @InjectMocks without manual setup.
Click to reveal answer
Which Maven scope should you use for Mockito dependency?
Atest
Bcompile
Cprovided
Druntime
Which Gradle configuration is correct for adding Mockito?
Aimplementation 'org.mockito:mockito-core:5.4.0'
BcompileOnly 'org.mockito:mockito-core:5.4.0'
CruntimeOnly 'org.mockito:mockito-core:5.4.0'
DtestImplementation 'org.mockito:mockito-core:5.4.0'
What annotation enables Mockito support in JUnit 5?
A@RunWith(MockitoJUnitRunner.class)
B@MockitoTest
C@ExtendWith(MockitoExtension.class)
D@MockSupport
Which version of Mockito is recommended for use with JUnit 5?
A5.x
B2.x
C3.x
D1.x
Why do we use mock objects in unit testing?
ATo test the real database
BTo simulate dependencies and isolate the unit under test
CTo slow down tests
DTo replace the entire application
Explain how to set up Mockito dependency in a Java project using Maven or Gradle.
Think about where to add dependencies in build files and the scope for test libraries.
You got /3 concepts.
    Describe the role of the @ExtendWith(MockitoExtension.class) annotation in JUnit 5 tests.
    Consider how JUnit 5 integrates with Mockito to simplify test setup.
    You got /3 concepts.