如何开启Robolectric日志记录功能

13

我需要一个非常简单的方法来启用 Robolectric 3.0 的日志记录。我想看到来自Robolectric的输出,而不仅仅是我的测试输出。我尝试过网上的所有方法都不起作用。

我应该把它放在哪里?

robolectric.logging.enabled = true

我尝试了以下方法:

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

在 test/java/resources 目录下的 robolectric.properties 文件中

在 test/res 目录下的 robolectric.properties 文件中

在 test/resources 目录下的 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')
}

当你说“logging”时,你期望看到什么?测试的输出吗? - Jared Burrows
我将编辑问题。我想看看Robolectric在做什么。我想知道ContextImpl.ensureDirsExistOrFilter()在底层做了什么。 - LEO
这个有什么进展了吗? - Jared Burrows
1个回答

20

稍微解释一下:ShadowLog.stream = System.out,只记录了我的测试,但Gradle的添加记录了所有内容,包括Robolectric材料和我的个人测试材料。 - LEO
太好了!感谢您的确认。 - Jared Burrows
只有使用ShadowLog的第一个选项对我有效。添加这个后,我可以在终端上看到来自应用程序中所有Log语句的日志输出。 - slott
构建.gradle的建议对于使用Gradle 2的Roboelectric 3.0有效吗?当我尝试这样做时,它不起作用,并且Android Studio警告无法解析'systemProperty'。 - sidecarcat
@sidecarcat 请通过命令行使用 gradlew,不要依赖 Android Studio。您正在使用哪个版本的 gradle?那不是我的例子。在这里查看TestsystemProperty:https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html。 - Jared Burrows
显示剩余4条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接