I am trying to run a unit test in groovy. The test class itself never gets called.
My build.gradle is below:
apply plugin: 'groovy'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url 'https://repo.jenkins-ci.org/releases/' }
}
dependencies {
implementation 'org.codehaus.groovy:groovy-all:3.0.7'
testImplementation 'junit:junit:4.12'
testImplementation "com.lesfurets:jenkins-pipeline-unit:1.3"
}
tasks.withType(Test) {
testLogging {
exceptionFormat "full"
events "started", "skipped", "passed", "failed"
showStandardStreams true
}
}
test {
useJUnitPlatform()
testLogging {
events 'passed', 'skipped', 'failed'
}
// 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 }
}
// show summary
doLast {
println "Tests: ${results.sum { it.testCount }}" +
", Failures: ${results.sum { it.failedTestCount }}" +
", Errors: ${results.sum { it.exceptions.size() }}" +
", Skipped: ${results.sum { it.skippedTestCount }}"
}
}
My folder structure is as below :
src
---main
---groovy
---<groovy class>
---test
---groovy
---testClass.groovy
When I run .gradlew test then my console shows
Task :test
Tests: null, Failures: null, Errors: null, Skipped: null
BUILD SUCCESSFUL in 5s
4 actionable tasks: 2 executed, 2 up-to-date
The tests are null eventhough I have declared a test class in groovy.
Could someone help in executing gradle test.
The file name and class name were different due to which it wasn't getting called. It started working once I gave it the correct name.