|
Project Information
Featured
Downloads
Links
|
IntroductionStandard android test runner does not produce a very usable output from tests, if you want to process the output and produce some useful reports. This is for example where you run android tests using Jenkins/Hudson/Bamboo. All these are capable of parsing standard XML junit output and presenting it in a nice way. Current version is to be downloaded in the Download session. Changes are described in ReleaseNotes. The runnerThe missing junit test runner provides that capability. As opposed to some other projects, the runner is built as an Instrumentation Test runner, thanks to that you can use all the android standard command line parameters, that you would normally use. You can run only small or only big tests, you can run emma coverage tests and whatever else android test framework lets you do. RunningThe test runner should be added to the test project. Either as a .jar file (added in libs directory) or as external library (standard android external library approach). You can download the .jar file from here In order to use the runner you need to:
<instrumentation android:name="pl.polidea.instrumentation.PolideaInstrumentationTestRunner"
android:targetPackage="pl.polidea.somepackage"
android:label="Tests for pl.polidea.somepackage"/>adb shell am instrument -w somepackage/pl.polidea.instrumentation.PolideaInstrumentationTestRunner or with extra parameters: adb shell am instrument -e junitSplitLevel class -w somepackage/pl.polidea.instrumentation.PolideaInstrumentationTestRunner More info about running test runners can be found here. You can also use standard android test tasks. Your build.xml might look like: <project name="Test" default="help">
<property file="local.properties" />
<property file="build.properties" />
<property file="default.properties" />
<import file="${sdk.dir}/tools/ant/pre_setup.xml" />
<property name="test.runner" value="pl.polidea.instrumentation.PolideaInstrumentationTestRunner" />
<setup import="no" />
<import file="${sdk.dir}/tools/ant/test_rules.xml" />
</project>and then you can execute "ant run-tests" or "ant coverage". Supported parametersThe parameters supported by runner are:
Getting the JUnit resultsXML files are generated on the device (or emulator) in /data/data/<YOUR_APP_PACKAGE>/files/ and you need to download the files after test using adb pull in order to process them. This can be done with command line or step similar to the following added to the build: <exec executable="${adb}" failonerror="true" dir="junit-results">
<arg line="${adb.device.arg}" />
<arg value="pull" />
<arg value="/data/data/${tested.manifest.package}/files/" />
</exec>There is one file generated per each package containing test case classes (potentially containing multiple test case classes). Analysing the resultsThe XML produced by the runner is compatible with standard junit generated files. It can be displayed by various plugins of CI servers (Jenkins/Hudson/Bamboo). You can also import it into Junit view of eclipse and display the results there (including ability to click-to-go-to-source code) |