Skip to content

Commit

Permalink
Use test-suites for cross version tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leonard84 committed Feb 16, 2023
1 parent 2cb065e commit c97a384
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 49 deletions.
50 changes: 27 additions & 23 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}

Expand Down Expand Up @@ -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'
}
Expand Down Expand Up @@ -200,7 +204,7 @@ subprojects {
}

jacoco {
toolVersion = libs.jacocoAgent.version
toolVersion = jacocoVersion
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,3 @@ class JavaSpies extends Specification {
}
}
}
107 changes: 82 additions & 25 deletions spock-spring/spring.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
plugins {
id 'jvm-test-suite'
}

apply from: script("publishMaven")

ext.displayName = "Spock Framework - Spring Module"
Expand All @@ -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 {
Expand Down

0 comments on commit c97a384

Please sign in to comment.