我试图按照这篇文章将更多日志打印到我的控制台: /sf/answers/2529132721/,但我不断收到这些错误:
这是我的代码
构建.gradle 文件:
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'java'
repositories {
jcenter()
mavenCentral()
}
tasks.withType(Test) {
testLogging {
// set options for log level LIFECYCLE
events TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_OUT
exceptionFormat TestExceptionFormat.FULL
showExceptions true
showCauses true
showStackTraces true
// set options for log level DEBUG and INFO
debug {
events TestLogEvent.STARTED,
TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_ERROR,
TestLogEvent.STANDARD_OUT
exceptionFormat TestExceptionFormat.FULL
}
info.events = debug.events
info.exceptionFormat = debug.exceptionFormat
afterSuite { desc, result ->
if (!desc.parent) { // will match the outermost suite
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
def startItem = '| ', endItem = ' |'
def repeatLength = startItem.length() + output.length() + endItem.length()
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
}
}
}
}
dependencies {
testImplementation group: 'org.codehaus.groovy', name: 'groovy-all', version:'2.4.10'
testImplementation group: 'org.spockframework', name: 'spock-unitils', version:'1.1-groovy-2.4-rc-4'
}
Run Code Online (Sandbox Code Playgroud)
使用JUnit 5和Gradle 6,以下test任务定义将打印测试的名称和结果:
test {
useJUnitPlatform()
testLogging.events.addAll([TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED])
}
Run Code Online (Sandbox Code Playgroud)
如果您想要获得有关测试结果的聚合信息,可以使用以下版本的任务test。所有测试完成后将添加以下报告。
----------------------------------------------------------------------
| Results: SUCCESS (95 tests, 95 successes, 0 failures, 0 skipped) |
----------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
test {
useJUnitPlatform()
testLogging.events.addAll([TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED])
testLogging {
afterSuite { desc, result ->
if (!desc.parent) { // group the results in one
def output = "Results: ${result.resultType} (" +
"${result.testCount} tests, " +
"${result.successfulTestCount} successes, " +
"${result.failedTestCount} failures, " +
"${result.skippedTestCount} skipped)"
def startItem = '| ', endItem = ' |'
def repeatLength = startItem.length() + output.length() + endItem.length()
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我建议查看这些文档:
| 归档时间: |
|
| 查看次数: |
2148 次 |
| 最近记录: |