问题
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