I'm porting a C++ application with unit tests written in the same
language. The unit test framework is embedded as part of the
executable, and the results are written as a textual report to stderr
(though it could of course be directed elsewhere). I need to be able
to automatically launch the application remotely and capture the
results on my development machine for processing.
What would be a nice scheme for the above? I've got everything except
the unit testing part set up. I guess I could use the <android/log.h>
functions and extract the results from the system log, or write the
results to a file which I then transfer to my development machine -
but both of those approaches feel a bit more tedious than they ought
to be. Is there something nicer available?
Thanks,
Ulf
__android_log_* functions are pretty handy. The tag argument allow you to group
the output. So you could use a specific tag for your unit tests, say "MyUnitTests".
For automating your tests, you can write a small script like:
$ adb install -r your.apk
$ adb shell "am start -a android.intent.action.MAIN -n com.your.app/.SomeActivity"
$ adb logcat MyUnitTests:D '*':S | tee testlog.txt
The logcat command supports a variety of options, see:
http://developer.android.com/guide/developing/tools/adb.html#logcat
Hope that helps
--
Olivier
That's very helpful - thanks! I never realized the logging system was
that flexible. I guess a simple scheme would be to clear the log (to
avoid picking up results from previous runs), run the application
remotely, and then examine the output of logcat, filtered on a
unit-test-specific tag.
/Ulf
#!/bin/bash
...
# Test
if $doTest
then
Progress "Testing"
case $testTarget in
images) flags=--write_images ;;
esac
$verbose && flags="$flags --verbose"
flags="$flags $flagArgs"
num_tests=0
num_failed=0
case ${machDir} in
android) cd "${F_HOME}/bin/${machDir}/release"
esac
for test in $testList
do
adb push ${test} /data/local/tmp || ExitOnError "Pushing ${test} to device"
done
for test in $testList
do
num_tests=`expr $num_tests + 1`
adb shell "export LD_LIBRARY_PATH=.; cd /data/local/tmp; ./${test} --gtest_color=yes --out_dir=/sdcard/gtest ${flags}" | tee /tmp/TMP$$
grep -q '\[ FAILED \]' /tmp/TMP$$ && num_failed=`expr $num_failed + 1`
done
rm -f /tmp/TMP$$
;;
*) cd "${F_HOME}/bin/${machDir}/${buildType}"
for test in $testList
do
num_tests=`expr $num_tests + 1`
./$test $flags || num_failed=`expr $num_failed + 1`
done
;;
esac
test $num_failed = 0 && echo -e "\n${GREEN_COLOR}ALL $num_tests TESTS PASSED.${END_COLOR}\n" \
|| { echo -e "\n${RED_COLOR}$num_failed TESTS FAILED, ${GREEN_COLOR}`expr $num_tests - $num_failed` TESTS PASSED.${END_COLOR}\n"; exit 1; }
fi
> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
>