如何打开 robolectric 日志记录

How to turn on robolectric logging

我需要一种非常简单的方法来获取 Robolectric 3.0 以打开日志记录。我想查看 robolectric 的输出,而不仅仅是我的测试。我在网上试过的所有东西都不起作用。

我要把它贴在哪里?

robolectric.logging.enabled = true

我尝试了以下方法:

在 test/java/res 中的 robolectric.properties 文件中

在 test/java/res 源中的 robolectric.properties 文件中

在 test/res

的 robolectric.properties 文件中

在 test/res 源中的 robolectric.properties 文件中

在gradle中:

afterEvaluate {
    project.tasks.withType(Test) {
        systemProperties.put('robolectric.logging.enable', 'true')
    }
}

在gradle中:

tasks.withType(Test) {
    testLogging.exceptionFormat = 'full'
    systemProperties.put('robolectric.logging.enable', 'true')
}

您可以添加到您的测试中:

@Before
public void init() { 
    ShadowLog.stream = System.out;
}

然后使用:gradle test -i

来源:Unable to get log.d or output Robolectrict + gradle

或在build.gradle中添加:

tasks.withType(Test) { 
     systemProperty "robolectric.logging", "stdout" 
} 

来源:https://github.com/studyplus/Studyplus-Android-SDK/blob/master/StudyplusAndroidSDK/build.gradle#L41