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

Groovy 7 is not running my test when using gradlew clean test #578

Open
pteichner opened this issue Jan 5, 2023 · 4 comments
Open

Groovy 7 is not running my test when using gradlew clean test #578

pteichner opened this issue Jan 5, 2023 · 4 comments

Comments

@pteichner
Copy link

pteichner commented Jan 5, 2023

Jenkins and plugins versions report

Environment
Paste the output here

What Operating System are you using (both controller, and any agents involved in the problem)?

Intellij IDEA

Reproduction steps

  1. Create build.gradle
  2. Create function
  3. Create corresponding test
  4. Run gradlew clean test

Expected Results

Gradle should run tests

Actual Results

IT complies everything but doesn't run tests

Anything else?

No response

@pteichner
Copy link
Author

pteichner commented Jan 5, 2023

group 'com.****.jenkins.library'
version '1.0-SNAPSHOT'

apply plugin: 'groovy'
apply plugin: 'idea'

sourceCompatibility = 11
targetCompatibility = 11

idea {
    module {
        downloadJavadoc = true
        downloadSources = true
    }
}

sourceSets {
    main {
        groovy {
            srcDirs = ['src', 'vars']
        }
        resources {
            srcDir('resources')
        }
    }
    test {
        groovy {
            resources {
                srcDir('test')
            }
        }
    }
}

repositories {
    maven {
        url "***/maven-jenkins-release"
    }
    maven {
        url "***/maven-public"
    }
}

dependencies {
    // Jenkins core
    String JENKINS_VERSION = System.getenv('JENKINS_VERSION') ?: '2.303.3'
    String JENKINS_PIPELINE_UNIT_VERSION = "1.9"
    implementation group: 'org.jenkins-ci.main', name: 'jenkins-core', version: JENKINS_VERSION
    testImplementation group: 'org.jenkins-ci.main', name: 'jenkins-core', version: JENKINS_VERSION
    implementation group: 'com.lesfurets', name: 'jenkins-pipeline-unit', version: JENKINS_PIPELINE_UNIT_VERSION
    testCompileOnly group: "org.junit.vintage", name: "junit-vintage-engine", version: "5.9.1"

    // Test frameworks
    //testImplementation group: "org.junit.vintage", name: "junit-vintage-engine", version: "5.9.1"
    //testCompileOnly group: 'junit', name: 'junit', version: '4.13.1'
    testImplementation group: 'junit', name: 'junit', version: '4.13.1'
    testImplementation group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
    testImplementation group: 'com.lesfurets', name: 'jenkins-pipeline-unit', version: JENKINS_PIPELINE_UNIT_VERSION
    testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.5.13'
    implementation group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.6'
    implementation group: 'com.lesfurets', name: 'jenkins-pipeline-unit', version: JENKINS_PIPELINE_UNIT_VERSION

    // Jenkins plugins
    implementation group: 'com.cloudbees', name: 'groovy-cps', version: '1.32'
    implementation group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-step-api', version: '2.22', ext: 'jar'
    implementation group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-api', version: '2.40', ext: 'jar'
    implementation group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-cps', version: '2.83', ext: 'jar'
    implementation group: 'org.6wind.jenkins', name: 'lockable-resources', version: '2.12', ext: 'jar'
    implementation group: 'org.jenkins-ci.plugins', name: 'credentials', version: '2.6.1', ext: 'jar'

    // TRICKY: The lib folder contains all other plugins *JAR* files if not found in Maven
    //implementation fileTree(dir: 'lib', include: ['*.jar'])
}
test {
    include "**/**Test.class"
    useJUnit()

    testLogging {
        events "PASSED", "FAILED", "SKIPPED"
    }
    // delete old test reports
    dependsOn cleanTest

    // don't stop if tests fail
    ignoreFailures = true

    // minimize logging
    testLogging.maxGranularity = 0

    // show stdout from tests
    onOutput { dest, event -> print event.message }
    // show test results
    def results = []

    afterTest { desc, result ->
        println "${desc.className.split("\\.")[-1]}: " +
                "${desc.name}: ${result.resultType}"
    }

    afterSuite { desc, result ->
        if (desc.className) { results << result }
    }

    doLast {
        println "Tests: ${results.sum { it.testCount }}" +
                ", Failures: ${results.sum { it.failedTestCount }}" +
                ", Errors: ${results.sum { it.exceptions.size() }}" +
                ", Skipped: ${results.sum { it.skippedTestCount }}"
    }
}

@pteichner
Copy link
Author

src/test/CreateBuildInfoDescriptionTest.groovy

import com.lesfurets.jenkins.unit.BasePipelineTest
import org.junit.Before
import org.junit.Test

import static org.junit.Assert.assertEquals

class CreateBuildInfoDescriptionTest extends BasePipelineTest {
    def createBuildInfoDescription

    @Before
    void setUp() {
        super.setUp()
        // load toAlphanumeric
        createBuildInfoDescription = loadScript("vars/createBuildInfoDescription.groovy")
    }

    @Test
    void testCall() {
        // call toAlphanumeric and check result
        def asset = ["api":[version:"1"],"gui":[version:"2"]]
        def result = createBuildInfoDescription(asset)
        assertEquals("<ul><li>api: 1</li><li>gui: 2</li></ul>", result)
    }
}

@pteichner
Copy link
Author

vars.createBuildInfoDescription.groovy

#!groovy

def call(artifacts) {
    def description = "<ul>"

    artifacts.each() {
        description += "<li>${it.key}: ${it.value.version}</li>"
    }
    description += "</ul>"
    return description.toString()
}

@nre-ableton
Copy link
Contributor

I assume you mean "Gradle 7", since the latest Groovy version is 4.x. Anyways, I just merged a PR that updates to Gradle 8.x, please re-try and report back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants