我正在尝试在 groovy 中运行单元测试。测试类本身永远不会被调用。
我的 build.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 test 然后我的控制台显示
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 测试。