From e631d5161e2e7895d08ad0e73346434de15190b2 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Tue, 21 Jan 2025 13:12:05 +0000 Subject: [PATCH] add Mockito --- app/build.gradle.kts | 28 ++++++++++++++++++++-------- gradle/libs.versions.toml | 6 +++--- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index efbb5b8..af1ddc6 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -18,6 +18,7 @@ repositories { } val latestJmhVersion = "1.37" +val mockitoAgent = configurations.create("mockitoAgent") dependencies { // Use JUnit Jupiter for testing. @@ -27,6 +28,11 @@ dependencies { // Required to use the IntelliJ plugin "JMH Java Microbenchmark Harness". // https://stackoverflow.com/a/71286156/6334421 jmhAnnotationProcessor("org.openjdk.jmh:jmh-generator-annprocess:$latestJmhVersion") + + // 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. @@ -60,15 +66,21 @@ tasks.register("runCbmCompetition") { mainClass = "de.uni_marburg.powersort.benchmark.CbmCompetition" } -tasks.named("test") { - // Use JUnit Platform for unit tests. - useJUnitPlatform() +tasks { + test { + // Use JUnit Platform for unit tests. + useJUnitPlatform() - reports { - // XML reports for GitLab CI. - junitXml.required.set(true) - // HTML reports to view with a webbrowser. - html.required.set(true) + reports { + // XML reports for GitLab CI. + junitXml.required.set(true) + // HTML reports to view with a webbrowser. + html.required.set(true) + } + + // Mockito JDK21+ config + // https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#mockito-instrumentation + jvmArgs("-javaagent:${mockitoAgent.asPath}") } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 843e91d..dffb973 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,9 +2,9 @@ # https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format [versions] -guava = "32.1.3-jre" -junit-jupiter = "5.10.1" +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" }