如何在Android中打印标准输出以进行单元测试? [英] How do I print the stdout for unit test in Android?

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

问题描述

我需要一种快速的方法来进行一些测试,并且不想看Dalvik调试监视器.我只想创建一个快速的public static void main()并打印一些结果以进行调试.我以为我可以使用单元测试框架在控制台stdout上获得一些结果,但是System.out.println()仍然会进入日志(以及Log.d()).

I need a quick way to do a few tests and don't want to look at the Dalvik Debug Monitor. I just want to create a quick public static void main() and print some results to experiment with for debugging. I thought I could use the unit testing framework to get some results on the console stdout, but System.out.println() still goes to the log (as well as Log.d()).

那么在进行单元测试时有没有办法打印标准输出?

ant debug install test
test:
 [echo] Running tests ...
 [exec]
 [exec] com.MainTest:.
 [exec] Test results for InstrumentationTestRunner=.

推荐答案

我没有找到为单元测试启用stdout重定向的选项,但这是一种解决方法.运行单元测试后(或在单独的外壳窗口中),输入:

I didn't find the option to enable stdout redirection for a unit test, but here is a workaround. After running a unit test (or in a separate shell window) type:

adb logcat|grep System.out

在Windows上,可能应该是adb logcat | FINDSTR System.out

On Windows, it should probably be adb logcat | FINDSTR System.out

它将仅显示System.out语句,包括单元测试的输出.

It will only display System.out statements including the output of the unit test.

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

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