Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spock-based unit tests are not being run via Gradle #937

Open
nickdos opened this issue Jan 13, 2025 · 1 comment · Fixed by #938
Open

Spock-based unit tests are not being run via Gradle #937

nickdos opened this issue Jan 13, 2025 · 1 comment · Fixed by #938
Labels
Milestone

Comments

@nickdos
Copy link
Contributor

nickdos commented Jan 13, 2025

When running the unit tests via gradle (CI/CD build), only Junit tests are being executed. Attempting to manually run a Spock unit test via gradle test --tests "*Spec", results in an error message:

No tests found for given includes

I got them working as part of another issue, so including the build.gradle file below.

As many of these *Spec tests have not been run for a while, many are failing, so they need to be fixed or marked as ignored as part of this issue.

Adam suggests that the test file (src/test/java/au/org/ala/biocache/util/QueryFormatUtilsSpec.groovy):

Tests should be using the SOLR field names not the old names that get translated with the locally installed JSON config file. This appears to be a problem for existing tests as well as these new ones.


import java.time.Instant

/*
 * This file was generated by the Gradle 'init' task.
 */
//buildscript {
//    repositories {
//        mavenCentral()
//    }
//    dependencies {
//        classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.7.0'
//    }
//}

plugins {
    id 'java'
    id 'war'
    id 'maven-publish'
    id 'org.springframework.boot' version "2.7.3"
    id 'com.avast.gradle.docker-compose' version "0.16.9"
    id "com.gorylenko.gradle-git-properties" version "2.4.1"
    id 'jacoco'
    id 'com.github.kt3k.coveralls' version '2.12.0'
    id 'groovy'
//    id "com.github.nbaztec.coveralls-jacoco" version "1.2.15"
}

repositories {
    mavenLocal()
    maven {
        url = uri('https://nexus.ala.org.au/content/groups/public/')
    }

    maven {
        url = uri('https://oss.sonatype.org/content/repositories/snapshots')
    }

    maven {
        url = uri('https://repo.maven.apache.org/maven2/')
    }
}

group = 'au.org.ala'
version = '3.5.1-SNAPSHOT'


boolean inplace = false

configurations {

    all*.exclude group: 'ch.qos.logback'
    all*.exclude group: 'javax.servlet', module: 'servlet-api'
}

dependencies {

    compileOnly 'org.projectlombok:lombok:1.18.24'
    annotationProcessor 'org.projectlombok:lombok:1.18.24'
    developmentOnly 'org.springframework.boot:spring-boot-devtools:2.7.0'

//    implementation 'org.springframework.boot:spring-boot-starter-parent:2.7.0'

    implementation 'org.springframework.boot:spring-boot-starter-web:2.7.0'
    implementation 'org.apache.tomcat.embed:tomcat-embed-jasper:9.0.55'
    implementation 'org.springframework.boot:spring-boot-starter-cache:2.7.0'
    implementation 'org.springframework.boot:spring-boot-starter-actuator:2.7.0'
    implementation 'org.springframework.boot:spring-boot-starter-validation:2.7.0'
    implementation 'org.springframework:spring-oxm:5.3.13'

    implementation 'org.ehcache:ehcache:3.8.1'
    implementation 'org.apache.httpcomponents:httpclient-cache:4.5.13'
    implementation 'org.hibernate.validator:hibernate-validator:6.2.0.Final'
    implementation 'org.apache.solr:solr-solrj:8.11.2'
    implementation 'com.datastax.cassandra:cassandra-driver-core:3.11.0'
    implementation 'com.datastax.cassandra:cassandra-driver-extras:3.11.0'
    implementation 'com.fasterxml.jackson.core:jackson-core:2.13.0'
    implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.0'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'
    implementation 'org.geotools:gt-opengis:26.0'
    implementation 'org.geotools:gt-referencing:26.0'
    implementation 'org.geotools:gt-epsg-wkt:26.0'
    implementation 'au.org.ala.names:ala-namematching-client:1.8.1'
    implementation 'com.googlecode.json-simple:json-simple:1.1.1'
    implementation 'au.org.ala:ala-logger:1.4.1'
    implementation 'au.org.ala:ala-common-ui:1.0'
    implementation 'net.sf.opencsv:opencsv:2.3'
    implementation 'net.sf.ehcache:ehcache:2.10.9.2'
    implementation 'org.apache.httpcomponents:httpcore:4.4.14'
    implementation 'org.apache.httpcomponents:httpclient:4.5.13'
    implementation 'commons-lang:commons-lang:2.6'
    implementation 'commons-io:commons-io:2.7'
    implementation 'org.springdoc:springdoc-openapi-ui:1.5.12'
    implementation 'org.springdoc:springdoc-openapi-data-rest:1.5.12'
    implementation 'javax.servlet:jstl:1.2'
    implementation 'taglibs:standard:1.1.2'
    implementation 'com.jayway.jsonpath:json-path:2.4.0'
    implementation 'com.sun.mail:jakarta.mail:2.0.1'
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-client:2.7.0'
    implementation 'org.springframework.boot:spring-boot-starter-security:2.7.0'
    implementation 'org.springframework.boot:spring-boot-devtools:2.7.0'
    implementation 'commons-collections:commons-collections:3.2.2'
    implementation 'io.reactivex.rxjava3:rxjava:3.0.6'
    implementation 'opensymphony:sitemesh:2.4.2'
    implementation 'com.thoughtworks.xstream:xstream:1.4.18'
    implementation 'org.slf4j:slf4j-api:1.7.36'
    implementation 'org.slf4j:jul-to-slf4j:1.7.36'
    implementation 'org.slf4j:slf4j-log4j12:1.7.36'
    implementation 'org.apache.velocity:velocity:1.5'
    implementation 'org.json:json:20210307'
    implementation 'atg.taglib.json:json-taglib:0.4.1'
    implementation 'net.sf.json-lib:json-lib:2.2.3'
    implementation 'xmlpull:xmlpull:1.1.3.1'
    implementation 'commons-httpclient:commons-httpclient:3.1'
    implementation 'jfree:jfreechart:1.0.13'
    implementation 'com.squareup.retrofit2:retrofit:2.6.2'
    implementation 'com.squareup.retrofit2:converter-gson:2.6.2'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.3.1'
    implementation 'com.squareup.okhttp3:okhttp:4.3.1'
    implementation 'au.org.ala:data-quality-filter-service-client:1.0.0'
    implementation 'com.auth0:java-jwt:3.18.2'
    implementation 'com.auth0:jwks-rsa:0.20.0'
    implementation 'org.gbif:gbif-api:1.12.11'
    implementation 'org.gbif:dwc-api:1.47'
    implementation 'org.apache.commons:commons-compress:1.21'
    implementation 'com.google.code.findbugs:jsr305:3.0.2'
    implementation 'org.springframework.boot:spring-boot-autoconfigure:2.7.0'

    if (inplace) {
        implementation project(':ala-ws-spring-security')
        implementation project(':ala-ws-security')
    } else {
        implementation 'au.org.ala:ala-ws-spring-security:6.3.0-SNAPSHOT'
    }

    implementation 'org.codehaus.groovy:groovy-all:3.0.11'

    testImplementation 'org.codehaus.groovy:groovy-all:3.0.11'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1'
    testImplementation 'org.junit.jupiter:junit-jupiter-migrationsupport:5.9.1'
    testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.1'
    testImplementation 'org.junit.platform:junit-platform-launcher'
    testImplementation 'org.junit.platform:junit-platform-commons'
    testImplementation 'org.junit.vintage:junit-vintage-engine:5.9.1'
//    testImplementation 'junit:junit:4.13.1'
    testImplementation 'org.apiguardian:apiguardian-api:1.1.0'
    testImplementation 'org.mockito:mockito-core:3.4.4'
    testImplementation 'org.powermock:powermock-module-junit4:2.0.7'
    testImplementation 'org.powermock:powermock-api-mockito2:2.0.7'
    testImplementation 'org.spockframework:spock-core:2.3-groovy-3.0'
    testImplementation 'org.spockframework:spock-spring:2.3-groovy-3.0'
    testImplementation 'net.bytebuddy:byte-buddy:1.10.13'
    testImplementation 'org.hamcrest:hamcrest:2.1'
    testImplementation 'org.hamcrest:hamcrest-library:2.1'
    testImplementation 'org.springframework.security:spring-security-test:5.7.1'
    testImplementation 'com.squareup.retrofit2:retrofit-mock:2.6.2'
    testImplementation 'org.codehaus.groovy:groovy:2.5.14'
    testImplementation 'org.springframework:spring-tx:5.3.9'

    implementation 'javax.servlet:javax.servlet-api:4.0.1'
    implementation 'javax.servlet:jsp-api:2.0'

    providedRuntime 'javax.el:javax.el-api:3.0.0'
    providedRuntime 'org.glassfish:javax.el:3.0.0'
}

sourceSets {
    test {
        groovy {
            srcDirs = ['src/test/java']
        }
        java {
            srcDirs = ['src/test/java']
        }
    }
}

test {
    useJUnitPlatform()
    testLogging {
        events "passed", "skipped", "failed"
        exceptionFormat "full"
    }
}

bootWar {
    enabled = false
}

war {
    archiveClassifier = ''
}

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

gitProperties {
    extProperty = 'gitProps'
}

processResources {
    dependsOn('generateGitProperties')
    filesMatching('**/runtimeEnvironment.properties') {
        expand(
                build: [ timestamp: Instant.now() ],
                project: [ version: project.version ],
                spring: [ version: springVersion ],
                java: [ version: org.gradle.internal.jvm.Jvm.current() ],
        )
    }
    filesMatching('**/buildInfo.properties') {
        expand(
                git: [
                        commit: [
                                time: project.ext.gitProps['git.commit.time'],
                                id: project.ext.gitProps['git.commit.id'],
                                shortId: project.ext.gitProps['git.commit.id.abbrev']
                        ],
                        branch: project.ext.gitProps['git.branch'],
                        closest: [
                                tag: [
                                        name: project.ext.gitProps['git.closest.tag.name'],
                                        commit: [
                                                count: project.ext.gitProps['git.closest.tag.commit.count']
                                        ]
                                ]
                        ]
                ]
        )
    }
}

dockerCompose {
    useComposeFiles.add("src/test/resources/docker-compose.yaml")
    isRequiredBy(tasks.test)
}

test {
    finalizedBy 'jacocoTestReport' // report is always generated after tests run
}

jacocoTestReport {
    dependsOn 'test' // tests are required to run before generating the report
    reports {
        xml.enabled = true
        html.enabled = true
    }
}

tasks.coveralls {
    dependsOn 'check'
}

publishing {
    repositories {
        maven {
            name 'Nexus'
            url "https://nexus.ala.org.au/content/repositories/${project.version.endsWith('-SNAPSHOT') ? 'snapshots' : 'releases' }"
            credentials {
                username = System.getenv('TRAVIS_DEPLOY_USERNAME')
                password = System.getenv('TRAVIS_DEPLOY_PASSWORD')
            }
        }
    }
    publications {
        mavenJava(MavenPublication) {
//            from components.java
//            artifact sourcesJar
//            artifact javadocJar

            pom {
                name = 'Biocache Service'
                description = 'Occurrence & mapping webservices'
                url = 'https://github.com/AtlasOfLivingAustralia/biocache-service'
                licenses {
                    license {
                        name = 'MPL-1.1'
                        url = 'https://www.mozilla.org/en-US/MPL/1.1/'
                    }
                }
                developers {
                }
                scm {
                    connection = 'scm:git:git://github.com/AtlasOfLivingAustralia/biocache-service.git'
                    developerConnection = 'scm:git:ssh://github.com:AtlasOfLivingAustralia/biocache-service.git'
                    url = 'https://github.com/AtlasOfLivingAustralia/biocache-service'
                }
            }
            from components.web
        }
    }
}
@nickdos nickdos added the bug label Jan 13, 2025
@nickdos
Copy link
Contributor Author

nickdos commented Jan 13, 2025

Patch file:

Subject: [PATCH] [NCMIP-936] - Fix for Spock unit tests not running
---
Index: build.gradle
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/build.gradle b/build.gradle
--- a/build.gradle	(revision 6a50c911bc9c32b5f14be9ce31fdbaaffef15840)
+++ b/build.gradle	(date 1736734159299)
@@ -21,6 +21,7 @@
     id "com.gorylenko.gradle-git-properties" version "2.4.1"
     id 'jacoco'
     id 'com.github.kt3k.coveralls' version '2.12.0'
+    id 'groovy'
 //    id "com.github.nbaztec.coveralls-jacoco" version "1.2.15"
 }
 
@@ -125,27 +126,28 @@
     implementation 'org.springframework.boot:spring-boot-autoconfigure:2.7.0'
 
     if (inplace) {
-
         implementation project(':ala-ws-spring-security')
         implementation project(':ala-ws-security')
-
     } else {
-
         implementation 'au.org.ala:ala-ws-spring-security:6.3.0-SNAPSHOT'
     }
 
     implementation 'org.codehaus.groovy:groovy-all:3.0.11'
 
-    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
-    testImplementation 'org.junit.jupiter:junit-jupiter-migrationsupport:5.7.0'
-    testImplementation 'org.junit.vintage:junit-vintage-engine:5.7.0'
+    testImplementation 'org.codehaus.groovy:groovy-all:3.0.11'
+    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1'
+    testImplementation 'org.junit.jupiter:junit-jupiter-migrationsupport:5.9.1'
+    testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.1'
+    testImplementation 'org.junit.platform:junit-platform-launcher'
+    testImplementation 'org.junit.platform:junit-platform-commons'
+    testImplementation 'org.junit.vintage:junit-vintage-engine:5.9.1'
+//    testImplementation 'junit:junit:4.13.1'
     testImplementation 'org.apiguardian:apiguardian-api:1.1.0'
-    testImplementation 'junit:junit:4.13.1'
     testImplementation 'org.mockito:mockito-core:3.4.4'
     testImplementation 'org.powermock:powermock-module-junit4:2.0.7'
     testImplementation 'org.powermock:powermock-api-mockito2:2.0.7'
-    testImplementation 'org.spockframework:spock-core:2.0-groovy-2.5'
-    testImplementation 'org.spockframework:spock-spring:2.0-groovy-2.5'
+    testImplementation 'org.spockframework:spock-core:2.3-groovy-3.0'
+    testImplementation 'org.spockframework:spock-spring:2.3-groovy-3.0'
     testImplementation 'net.bytebuddy:byte-buddy:1.10.13'
     testImplementation 'org.hamcrest:hamcrest:2.1'
     testImplementation 'org.hamcrest:hamcrest-library:2.1'
@@ -161,7 +163,19 @@
     providedRuntime 'org.glassfish:javax.el:3.0.0'
 }
 
+sourceSets {
+    test {
+        groovy {
+            srcDirs = ['src/test/java']
+        }
+        java {
+            srcDirs = ['src/test/java']
+        }
+    }
+}
+
 test {
+    useJUnitPlatform()
     testLogging {
         events "passed", "skipped", "failed"
         exceptionFormat "full"

nickdos added a commit that referenced this issue Jan 16, 2025
@nickdos nickdos linked a pull request Jan 16, 2025 that will close this issue
nickdos added a commit that referenced this issue Jan 17, 2025
* #937 Gradle config fixes for Spock tests to run
* #937 Fixed broken test QueryFormatUtilsSpec.groovy
* #937 Fixed FieldMappedSolrClientSpecIT
* #937 Ignored test that fails with SOLR cluster
* #937 Attempt at fixing Travis test failure
* #938 More fixes for Travis tests failing
* #938 Revert LoggerRestService changes - Didn't help
* #938 Another attempt at fixing Travis test error
* #938 Set test to @ignore due to failing on Travis
* #938 @ignore LoggerServiceSpec - Is stalling Travis builds but working locally so difficult to debug
* #938 Removed println left in test code
@adam-collins adam-collins added this to the 3.6.0 milestone Jan 29, 2025
@nickdos nickdos reopened this Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants