Gradle不在groovy中运行单元测试



我正在尝试在groovy中运行单元测试。测试类本身永远不会被调用。

我的构建。Gradle如下:

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 }}" 
}
}

文件夹结构如下:

src
---main
---groovy
---<groovy class>
---test
---groovy
---testClass.groovy

当我运行。gradlew测试时,控制台显示

Task :test
Tests: null, Failures: null, Errors: null, Skipped: null
BUILD SUCCESSFUL in 5s
4 actionable tasks: 2 executed, 2 up-to-date

测试是空的,即使我已经在groovy中声明了一个测试类。

有没有人可以帮助执行gradle test.

文件名和类名不同,因此没有被调用。一旦我给了它正确的名字,它就开始工作了。

最新更新