终端上的Gradle堆栈跟踪

jslywgbw  于 2023-08-06  发布在  其他
关注(0)|答案(3)|浏览(105)

我需要在我的Java项目中使用Gradle。我正在用./gradlew test运行一些单元测试,但是异常堆栈跟踪是在一个我需要在浏览器中加载的网页上。
为什么这么复杂?
有没有办法让它在终端上,而不是像我玛文?

erhoui1w

erhoui1w1#

根据this page,将执行以下操作:

test {
    testLogging {
        exceptionFormat = 'full'
    }
}

字符串
这还真管用它并没有真正显示整个异常跟踪,但是(甚至更好?)它显示了它的相关部分(即与单元测试中编写的代码相关联的部分)。
以上在build.gradle.kts中的等价物

tasks.withType<Test> {
  useJUnitPlatform()
  testLogging { exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL }
}

rjee0c15

rjee0c152#

对于gradle(Kotlindsl),你可以这样做:

import org.gradle.api.tasks.testing.logging.TestExceptionFormat

tasks {
  test {
    testLogging {
        events("passed", "skipped", "failed")
        showStackTraces = true
        exceptionFormat = TestExceptionFormat.FULL
    }
  }
}

字符串

myzjeezk

myzjeezk3#

以下是我在Android项目中的工作。在模块级build.gradle文件(如app/build.gradle)中添加以下行:

plugins {
    // ...
}

android {
    // ...
}

tasks.withType(Test) {
    testLogging {
        exceptionFormat = 'full'

        // Optionally do:
        showStackTraces = true
    }
}

dependencies {
    // ...
}

字符串

相关问题