Challenge - 5 Problems
Mockito Dependency Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Understanding Mockito Dependency in Maven
Which Maven dependency snippet correctly adds Mockito version 4.11.0 to a JUnit 5 project?
Attempts:
2 left
💡 Hint
Mockito core is the main library; use the latest version and test scope for testing.
✗ Incorrect
Option A correctly uses mockito-core version 4.11.0 with test scope, which is the recommended setup for JUnit 5 projects. Option A uses mockito-all which is deprecated. Option A uses an older version and a different artifact. Option A uses an older version and wrong scope.
❓ Predict Output
intermediate2:00remaining
JUnit 5 Test Execution with Mockito Dependency
Given the following JUnit 5 test class using Mockito, what will be the test execution result if Mockito dependency is missing from the project?
JUnit
import org.junit.jupiter.api.Test; import org.mockito.Mockito; public class SampleTest { @Test void testMock() { Runnable mockRunnable = Mockito.mock(Runnable.class); Mockito.verify(mockRunnable, Mockito.never()).run(); } }
Attempts:
2 left
💡 Hint
Think about what happens if the Mockito classes are not found at runtime.
✗ Incorrect
Without the Mockito dependency, the JVM cannot find Mockito classes, causing a ClassNotFoundException during test execution.
❓ locator
advanced2:00remaining
Correct Mockito Dependency for Gradle Build
Which Gradle dependency line correctly adds Mockito version 4.11.0 for testing in a Java project?
Attempts:
2 left
💡 Hint
Mockito is used only during testing, so use the testImplementation configuration.
✗ Incorrect
Option B uses testImplementation which is correct for test dependencies in Gradle. Option B includes Mockito in main code which is unnecessary. Options A and C are incorrect scopes for Mockito usage.
❓ assertion
advanced2:00remaining
Mockito Version Compatibility Assertion
Which assertion correctly verifies that the Mockito version used in the project is at least 4.0.0 in a Java test?
JUnit
import static org.junit.jupiter.api.Assertions.assertTrue; import org.mockito.Mockito; public class VersionTest { @org.junit.jupiter.api.Test void testMockitoVersion() { String version = Mockito.class.getPackage().getImplementationVersion(); // Insert assertion here } }
Attempts:
2 left
💡 Hint
Use string comparison to check version is equal or higher than 4.0.0.
✗ Incorrect
Option C correctly asserts that the version string is lexicographically greater or equal to "4.0.0", ensuring version 4 or higher. Option C only checks if version starts with 4, which may miss minor versions. Option C requires exact match. Option C checks greater than 3.9.9 but excludes 4.0.0 itself.
❓ framework
expert3:00remaining
Mockito Extension Setup for JUnit 5
Which code snippet correctly enables Mockito annotations like @Mock in a JUnit 5 test class?
Attempts:
2 left
💡 Hint
JUnit 5 uses @ExtendWith for extensions, not @RunWith.
✗ Incorrect
Option A correctly uses @ExtendWith(MockitoExtension.class) to enable Mockito annotations in JUnit 5. Option A uses @RunWith which is for JUnit 4. Option A manually opens mocks but does not use the extension. Option A manually creates mocks without annotations.