From 5bf87c626493eb9ba78f43fc6b90dc7761f019a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20Br=C3=BCnings?= Date: Wed, 31 Aug 2022 16:07:20 +0200 Subject: [PATCH] Use test-suites for cross version tests --- build.gradle | 50 ++++---- .../smoke/mock/JavaSpies.groovy | 1 - spock-spring/spring.gradle | 107 ++++++++++++++---- 3 files changed, 109 insertions(+), 49 deletions(-) diff --git a/build.gradle b/build.gradle index 126a34825a..5d67a20009 100755 --- a/build.gradle +++ b/build.gradle @@ -59,28 +59,30 @@ ext { variantLessVersion = baseVersion + (snapshotVersion ? "-SNAPSHOT" : (milestone ? "-M$milestone" : "")) buildScan.tag "Java $javaVersion" + jacocoVersion = '0.8.8' + libs = [ - jetbrainsAnnotations: [group: "org.jetbrains", name: "annotations", version: "20.1.0"], - asm : [group: 'org.ow2.asm', name: 'asm', version: '9.2'], - bytebuddy : [group: 'net.bytebuddy', name: 'byte-buddy', version: '1.12.14'], - cglib : [group: 'cglib', name: 'cglib-nodep', version: '3.3.0'], + jetbrainsAnnotations: "org.jetbrains:annotations:20.1.0", + asm : "org.ow2.asm:asm:9.2", + bytebuddy : "net.bytebuddy:byte-buddy:1.12.14", + cglib : "cglib:cglib-nodep:3.3.0", groovy : groovyDependencies, - groovyNio : [group: groovyGroup, name: 'groovy-nio', version: groovyVersion], //for groovy methods on Path - groovySql : [group: groovyGroup, name: 'groovy-sql', version: groovyVersion], //for some Spring and Unitils tests - groovyTest : [group: groovyGroup, name: 'groovy-test', version: groovyVersion], //for @NotYetImplemented - groovyJmx : [group: groovyGroup, name: 'groovy-jmx', version: groovyVersion], //for triggering jacoco dump via jmx - h2database : [group: 'com.h2database', name: 'h2', version: '1.4.200'], - hamcrest : [group: 'org.hamcrest', name: 'hamcrest', version: '2.2'], - jaxb : [group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'], - junit4 : [group: 'junit', name: 'junit', version: '4.13.2'], - junitBom : [group: 'org.junit', name: 'junit-bom', version: '5.9.0'], - jupiter : [group: 'org.junit.jupiter', name: 'junit-jupiter'], - junitPlatform : [group: 'org.junit.platform', name: 'junit-platform-engine'], - junitPlatformTestkit: [group: 'org.junit.platform', name: 'junit-platform-testkit'], - junitPlatformConsole: [group: 'org.junit.platform', name: 'junit-platform-console'], - log4j : [group: 'log4j', name: 'log4j', version: '1.2.17'], - objenesis : [group: 'org.objenesis', name: 'objenesis', version: '3.3'], - jacocoAgent : [group: 'org.jacoco', name: 'org.jacoco.agent', version: '0.8.8', classifier: 'runtime'] + groovyNio : "$groovyGroup:groovy-nio:$groovyVersion", //for groovy methods on Path + groovySql : "$groovyGroup:groovy-sql:$groovyVersion", //for some Spring and Unitils tests + groovyTest : "$groovyGroup:groovy-test:$groovyVersion", //for @NotYetImplemented + groovyJmx : "$groovyGroup:groovy-jmx:$groovyVersion", //for triggering jacoco dump via jmx + h2database : "com.h2database:h2:1.4.200", + hamcrest : "org.hamcrest:hamcrest:2.2", + jaxb : "javax.xml.bind:jaxb-api:2.3.0", + junit4 : "junit:junit:4.13.2", + junitBom : "org.junit:junit-bom:5.9.0", + jupiter : "org.junit.jupiter:junit-jupiter", + junitPlatform : "org.junit.platform:junit-platform-engine", + junitPlatformTestkit: "org.junit.platform:junit-platform-testkit", + junitPlatformConsole: "org.junit.platform:junit-platform-console", + log4j : "log4j:log4j:1.2.17", + objenesis : "org.objenesis:objenesis:3.3", + jacocoAgent : "org.jacoco:org.jacoco.agent:$jacocoVersion:runtime" ] } @@ -122,8 +124,10 @@ subprojects { } tasks.withType(JavaCompile) { - javaCompiler = javaToolchains.compilerFor { - languageVersion = JavaLanguageVersion.of(8) + if (it.name == 'compileJava') { + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(8) + } } options.encoding = 'UTF-8' } @@ -200,7 +204,7 @@ subprojects { } jacoco { - toolVersion = libs.jacocoAgent.version + toolVersion = jacocoVersion } } diff --git a/spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaSpies.groovy b/spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaSpies.groovy index 607958791b..75367b8f0f 100644 --- a/spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaSpies.groovy +++ b/spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaSpies.groovy @@ -321,4 +321,3 @@ class JavaSpies extends Specification { } } } - diff --git a/spock-spring/spring.gradle b/spock-spring/spring.gradle index 302a0b1592..2d1ed1d1c5 100755 --- a/spock-spring/spring.gradle +++ b/spock-spring/spring.gradle @@ -1,3 +1,7 @@ +plugins { + id 'jvm-test-suite' +} + apply from: script("publishMaven") ext.displayName = "Spock Framework - Spring Module" @@ -6,41 +10,94 @@ description = "Spock's Spring Module makes it possible to use Spring's TestConte Supports Spring 2.5.x, 3.x, and 4.x." def springVersion = "4.3.5.RELEASE" - -if (springVersion.startsWith("2.")) { - sourceSets.test.groovy.exclude "**/*ContextHierarchyExample.groovy" -} +def testSpringVersions = [ + (springVersion): (8..11), + "5.0.2.RELEASE": (8..11), + "6.0.0" : (17..17) +].findAll { javaVersion in it.value }.keySet() dependencies { api project(":spock-core") compileOnly "org.springframework:spring-test:$springVersion" compileOnly "org.springframework:spring-beans:$springVersion" compileOnly "org.springframework:spring-context:$springVersion" - - // not used directly at implementation-time, but needed by groovyc - testImplementation "org.springframework:spring-test:$springVersion" - testImplementation "org.springframework:spring-beans:$springVersion" - testImplementation "org.springframework:spring-context:$springVersion" - testImplementation "org.springframework:spring-core:$springVersion" - testImplementation "org.springframework:spring-jdbc:$springVersion" - testImplementation "org.springframework:spring-tx:$springVersion" - testImplementation "javax.inject:javax.inject:1" - testImplementation libs.groovySql // for groovy.sql.Sql - testImplementation libs.junitPlatformTestkit - - testRuntimeOnly libs.h2database - testRuntimeOnly libs.log4j - testRuntimeOnly libs.bytebuddy - testRuntimeOnly libs.cglib - testRuntimeOnly libs.objenesis } -task testCglib(type: Test) { - systemProperty("org.spockframework.mock.ignoreByteBuddy", "true") - mustRunAfter test +testing { + suites { + all { + useJUnitJupiter() + dependencies { + implementation "javax.inject:javax.inject:1" + implementation libs.groovySql // for groovy.sql.Sql + implementation libs.junitPlatformTestkit + runtimeOnly libs.h2database + runtimeOnly libs.log4j + runtimeOnly libs.bytebuddy + runtimeOnly libs.cglib + runtimeOnly libs.objenesis + } + } + + test { + targets { + all { + testTask.configure { + onlyIf { false } //skip normal test task + } + } + } + } + + // Add a variant for each combination of spring version and cglib, if cglib is supported + def cgLibVariants = javaVersion <= 16 ? [false, true] : [false] + [testSpringVersions, cgLibVariants].combinations().each { testSpringVersion, forceCgLib -> + String testTaskName = "spring${testSpringVersion.charAt(0)}${(forceCgLib ? 'CgLib' : '')}Test" + "$testTaskName"(JvmTestSuite) { + + sources { + java { + srcDir 'src/test/java' + } + groovy { + srcDir 'src/test/groovy' + } + resources { + srcDir 'src/test/resources' + } + } + + dependencies { + implementation project(project.path) + implementation "org.springframework:spring-test:$testSpringVersion" + implementation "org.springframework:spring-beans:$testSpringVersion" + implementation "org.springframework:spring-context:$testSpringVersion" + implementation "org.springframework:spring-core:$testSpringVersion" + implementation "org.springframework:spring-jdbc:$testSpringVersion" + implementation "org.springframework:spring-tx:$testSpringVersion" + } + + // ideally we would just define another test task for this suite, but jvm-test-suites doesn't support that yet + if (forceCgLib) { + targets { + all { + testTask.configure { + systemProperty("org.spockframework.mock.ignoreByteBuddy", "true") + } + } + } + } + } + check.dependsOn testTaskName + } + } } -check.dependsOn testCglib +["compileTestJava", "compileTestGroovy"].each { taskName -> + tasks.named(taskName).configure { + onlyIf { false } //skip normal test task + } +} jar { manifest {