【问题标题】:How to turn on robolectric logging如何打开 robolectric 日志记录
【发布时间】:2015-08-07 18:56:06
【问题描述】:

我需要一种非常简单的方法来让 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')
}

【问题讨论】:

  • 当您的意思是“记录”时,您希望看到什么?测试的输出?
  • 我将编辑问题。我想看看 robolectric 在做什么。我想知道 ContextImpl.ensureDirsExistOrFilter() 在幕后做了什么。
  • 这是什么状态?

标签: android unit-testing robolectric


【解决方案1】:

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

@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

【讨论】:

  • 为了更清楚一点:ShadowLog.stream = System.out,只记录我的测试,但 gradle 添加记录了所有内容,robolectric 材料和我的个人测试材料。
  • 太棒了!感谢您的确认。
  • 只有 ShadowLog 的第一个选项对我有用。添加后,我可以从应用程序中的所有日志语句中获取日志输出,并打印到终端。
  • 这个问题怎么样?你能帮我解决这个问题吗? stackoverflow.com/questions/35726314/…
  • build.gradle 建议对带有 Gradle 2 的 Roboelectric 3.0 是否有效?当我尝试这个时,它不起作用,Android Studio 警告它无法解析“systemProperty”
猜你喜欢
  • 2017-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多