How do I print the stdout for unit test in Android?

混江龙づ霸主 提交于 2019-12-24 03:11:46

问题


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()).

So is there a way to print the the stdout when running a unit test?

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

回答1:


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

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

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



来源:https://stackoverflow.com/questions/12170429/how-do-i-print-the-stdout-for-unit-test-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!