如何在Android单元测试中打开控制台输出? [英] How to turn on console output in Android Unit tests?

查看:402
本文介绍了如何在Android单元测试中打开控制台输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在控制台输出中打开测试日志记录吗?

Is there any way to turn on the test logging in the console output?

我知道我们可以查看HTML文件中生成的测试结果并检查其中的标准输出,但是我发现这有点不方便.

I know that we can look at the test results generated in a HTML file and check standard output there, but I find it a little bit inconvinient.

我知道可以使用标准的Java插件来做到这一点:

I know that there is a way to do this with standard java plugin:

test {
    testLogging {
        events "passed", "skipped", "failed", "standardOut", "standardError"
    }
}

但是在Android项目中使用它会导致错误:

But using it in an Android project causes an error:

Could not find method test()

当然,应用Java插件是不可接受的,因为它与Android插件不兼容.

Applying java plugin is unacceptable, of course, as it's not compatible with Android plugins.

推荐答案

android {

...

  testOptions {
        unitTests.all {
        // All the usual Gradle options.
            testLogging {
                events "passed", "skipped", "failed", "standardOut", "standardError"
                outputs.upToDateWhen {false}
                showStandardStreams = true
            }
        }
    } 
}

就我而言,我遵循了此文档,如上所述添加了testLogging选项.这应该打印出写在src/test文件夹下而不是src/androidTest文件夹下的单元测试的日志.目前,我正在使用Android Studio 2.0预览版和gradle 2.8.命令是./gradlew test./gradlew test --continue,它们在iTerm 2中运行.

In my case, I followed this document and added the testLogging option as above. This should printout the log for the unit tests written under src/test folder but not the src/androidTest one. At the moment of this answer, I was using Android Studio 2.0 preview and gradle 2.8. The commands were ./gradlew test and ./gradlew test --continuein which ran in iTerm 2.

这篇关于如何在Android单元测试中打开控制台输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆