diff --git a/mockito-tutorial/app/build.gradle.kts b/mockito-tutorial/app/build.gradle.kts index 424b78f9..1bc83797 100644 --- a/mockito-tutorial/app/build.gradle.kts +++ b/mockito-tutorial/app/build.gradle.kts @@ -15,11 +15,17 @@ repositories { mavenCentral() } +val mockitoAgent = configurations.create("mockitoAgent") + dependencies { // Use JUnit Jupiter for testing. testImplementation(libs.junit.jupiter) - testRuntimeOnly("org.junit.platform:junit-platform-launcher") + + // Use Mockito for mocking. + // https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#mockito-instrumentation + testImplementation(libs.mockito) + mockitoAgent(libs.mockito) { isTransitive = false } } // Apply a specific Java toolchain to ease working on different environments. @@ -34,7 +40,13 @@ application { mainClass = "quality.software.Main" } -tasks.named("test") { - // Use JUnit Platform for unit tests. - useJUnitPlatform() -} +tasks { + test { + // Use JUnit Platform for unit tests. + useJUnitPlatform() + + // Mockito JDK21+ config + // https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#mockito-instrumentation + jvmArgs("-javaagent:${mockitoAgent.asPath}") + } +} \ No newline at end of file diff --git a/mockito-tutorial/gradle/libs.versions.toml b/mockito-tutorial/gradle/libs.versions.toml index 239e149e..36adaf95 100644 --- a/mockito-tutorial/gradle/libs.versions.toml +++ b/mockito-tutorial/gradle/libs.versions.toml @@ -4,7 +4,9 @@ [versions] guava = "33.2.1-jre" junit-jupiter = "5.10.3" +mockito = "5.14.0" [libraries] guava = { module = "com.google.guava:guava", version.ref = "guava" } junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" } +mockito = { module = "org.mockito:mockito-core", version.ref = "mockito" }