rob*_*oby 78
apply plugin : 'java'
test {
testLogging.showStandardStreams = true
}
Run Code Online (Sandbox Code Playgroud)
http://gradle.org/docs/current/dsl/org.gradle.api.tasks.testing.Test.html
这需要当前的gradle版本.我假设Scala测试是在Java测试任务下运行的.
To *_*Kra 20
我也在使用(testLogging.exceptionFormat = 'full'
):
test {
testLogging.showStandardStreams = true
testLogging.exceptionFormat = 'full'
}
Run Code Online (Sandbox Code Playgroud)
从stacktrace中可以看到更多内容
jos*_*ell 16
如果你在android gradle文件中(如果你在build.gradle文件apply plugin: 'com.android.application'
的顶部)
然后将其粘贴到build.gradle中
// Test Logging
tasks.withType(Test) {
testLogging {
events "standardOut", "started", "passed", "skipped", "failed"
}
}
Run Code Online (Sandbox Code Playgroud)
将其粘贴到build.gradle中
// Test Logging
test {
testLogging {
showStandardStreams = true
}
}
Run Code Online (Sandbox Code Playgroud)
nmf*_*one 15
正如@roby回答:
将以下代码添加到您的 build.gradle
apply plugin : 'java'
test {
testLogging.showStandardStreams = true
}
Run Code Online (Sandbox Code Playgroud)
重要!
您需要运行gradle test或使用添加的clean
命令构建.
./gradlew clean test
or
./gradlew clean build
Run Code Online (Sandbox Code Playgroud)
希望有效.
Syl*_*are 14
如果您使用 Kotlin DSL,build.gradle.kts
语法会有点不同。
确保您的依赖项中有 junit:
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.4.2")
testImplementation("org.junit.jupiter:junit-jupiter-api")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}
Run Code Online (Sandbox Code Playgroud)
然后你需要添加到你的测试任务中:
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
tasks.test {
useJUnitPlatform()
testLogging {
showStandardStreams = true
exceptionFormat = TestExceptionFormat.FULL
events("skipped", "failed")
}
}
Run Code Online (Sandbox Code Playgroud)
然后您可以根据需要调整设置。
对于 Android Gradle:/sf/answers/2969807081/
对于 Android Gradle KTS(Kotlin):
// Test Logging
tasks.withType<Test> {
testLogging {
events("standardOut", "started", "passed", "skipped", "failed")
}
}
Run Code Online (Sandbox Code Playgroud)
test {
testLogging.showStandardStreams = true
}
Run Code Online (Sandbox Code Playgroud)
和
test {
testLogging {
showStandardStreams = true
}
}
Run Code Online (Sandbox Code Playgroud)
也有效.
只是补充一下,:
showStandardStreams = true
Run Code Online (Sandbox Code Playgroud)
是一个简写:
events = ["standard_out", "standard_error"]
Run Code Online (Sandbox Code Playgroud)
在将两个条目混合时,请务必记住以下内容:
test {
testLogging {
showStandardStreams = true
events = ["passed", "failed", "skipped"]
}
}
Run Code Online (Sandbox Code Playgroud)
将导致没有stdout而反向顺序:
test {
testLogging {
events = ["passed", "failed", "skipped"]
showStandardStreams = true
}
}
Run Code Online (Sandbox Code Playgroud)
将stdout条目添加到列表中,因此stdout将起作用.
有关详细信息,请参阅源.