Improved Android UI tests with zip logs and better verbosity

This commit is contained in:
Sylvain Berfini 2014-12-16 10:49:56 +01:00
parent defed46e45
commit cbc3c99703
3 changed files with 65 additions and 35 deletions

View file

@ -1,6 +1,5 @@
all:
ant debug
ant installd
ant debug install
run-all-tests: all
ant test

View file

@ -1,20 +1,17 @@
SDK_PATH=$(shell dirname `which android`)
SDK_PLATFORM_TOOLS_PATH=$(shell dirname `which adb`)
run-basic-tests:
clean:
$(SDK_PLATFORM_TOOLS_PATH)/adb uninstall org.linphone.test
$(SDK_PLATFORM_TOOLS_PATH)/adb uninstall org.linphone
$(SDK_PATH)/android update test-project --path . -m ../
ant debug
ant installd
adb shell am instrument -w -e size small org.linphone.test/com.zutubi.android.junitreport.JUnitReportTestRunner
adb shell run-as org.linphone cat /data/data/org.linphone/files/junit-report.xml > linphone-junit-report.xml
run-all-tests:
$(SDK_PLATFORM_TOOLS_PATH)/adb uninstall org.linphone.test
$(SDK_PLATFORM_TOOLS_PATH)/adb uninstall org.linphone
$(SDK_PATH)/android update test-project --path . -m ../
ant debug
ant installd
all: clean
ant debug install
run-basic-tests: all
ant test
run-all-tests: all
adb shell am instrument -w -e size large org.linphone.test/com.zutubi.android.junitreport.JUnitReportTestRunner
adb shell run-as org.linphone cat /data/data/org.linphone/files/junit-report.xml > linphone-junit-report.xml

View file

@ -1,26 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules">
<target name="test">
<exec executable="adb" failonerror="true" outputproperty="tests.output">
<arg value="shell" />
<arg value="am" />
<arg value="instrument" />
<arg value="-w" />
<arg value="-e" />
<arg value="size" />
<arg value="small" />
<arg value="org.linphone.test/android.test.InstrumentationTestRunner" />
</exec>
<echo message="${tests.output}"/>
<fail message="Tests failed">
<condition>
<contains string="${tests.output}" substring="FAILURES" />
</condition>
</fail>
<fail message="Tests crashed">
<condition>
<contains string="${tests.output}" substring="INSTRUMENTATION_CODE:" />
</condition>
</fail>
</target>
<property name="output.file" value="./tests.output" />
<tstamp>
<format property="archive.name"
pattern="'linphonetester_'yyyyMMdd_HHmmss" />
</tstamp>
<echo>Adb log files are put in ${archive.name}.zip</echo>
<exec executable="adb" >
<arg value="logcat" />
<arg value="-c" />
</exec>
<exec executable="./adb-log-start.sh" >
<arg value=" ${archive.name}" />
</exec>
<exec executable="bash">
<arg value="-c"/>
<!-- use 'tee' command to write in file AND on stdout.
First is used below to check if tests failed or not while second
is used to get output in real time -->
<arg value="adb shell am instrument -r -w -e size small org.linphone.test/com.zutubi.android.junitreport.JUnitReportTestRunner | tee ${output.file}"/>
</exec>
<exec executable="bash" >
<arg value="-c" />
<arg value="kill `cat adb.pid`" />
</exec>
<exec executable="bash">
<arg value="-c"/>
<arg value="adb shell run-as org.linphone cat /data/data/org.linphone/files/junit-report.xml > linphone-junit-report.xml"/>
</exec>
<zip destfile="${archive.name}.zip">
<fileset dir="." includes="${archive.name}"/>
</zip>
<fail message="Tests failed">
<condition>
<resourcecontains resource="${output.file}" substring="FAILURES" />
</condition>
</fail>
<condition property="has.crashed" >
<resourcecontains resource="${output.file}" substring="Process crashed" />
</condition>
<antcall target="check-for-crash"/>
<delete file="${archive.name}"/>
<delete file="${output.file}"/>
</target>
<target name="check-for-crash" if="has.crashed">
<exec executable="bash" >
<arg value="-c" />
<arg value="tail -n 500 ${archive.name}" />
</exec>
<exec executable="bash" >
<arg value="-c" />
<arg value="cat ${archive.name} |ndk-stack -sym obj/local/`adb shell getprop ro.product.cpu.abi | tr -d '\r'`" />
</exec>
<fail message="Tests crashed"/>
</target>
</project>