Since I did not find the answer to this particular question, I researched. Here is the result of my research and a quick How-To to help people perform automated functional tests in Android applications using robotium, and then report the results to a continuous integration server such as TeamCity. Please note that this may not be the best solution, but I felt that people could be in the same situation as me. So there it is!
The following libraries were used:
- Robotium ( https://code.google.com/p/robotium/ ): This is an Android testing automation platform. This helps you perform automated tests, such as clicking on buttons, automatically filling in text, and more.
- Android Junit Report ( http://zutubi.com/source/projects/android-junit-report/ ): This library is very useful for publishing test results in usable XML format. If you want to run tests through Eclipse, you will see the results of your tests on the go, but this library is very useful for exporting them.
Assuming you have an Android project for testing, create an Android test project (Eclipse has a good workflow to create for you) and set it up to work with Robotium. A fairly clear detailed instruction on how to do this can be found here: https://code.google.com/p/robotium/wiki/Getting_Started
Then you need to add the Android Junit report to your project in order to get the results of your tests. To do this, add the Android Junit Report * .jar library to your lib folder and add it to your build path (in Eclipse: Project → Properties → Java Build Path → Libraries → Add External Jar).
You must also change the test runner of your project. In the AndroidManifest.xml of your test project, add the following:
<instrumentation android:name="com.zutubi.android.junitreport.JUnitReportTestRunner" android:targetPackage="<insert your package ex:com.alth.myproject" />
Once this is done, you will be able to correctly perform your tests. Test results should be available on your device (in the following folder / data / data // files / junit -report.xml)
The next step is to configure the TeamCity build steps to complete all the necessary steps to complete your tests. Please note that my solution may not be optimal!
Build Step 1: Clean - The command line line. This build step may not be necessary depending on how you decide to create the build.xml files and such build solutions.
rm -rf <report folder> rm -rf <Project build.xml> rm -rf <Test project build.xml> android update project -p <Path to your project> android update test-projecct -m <Path to your project, relative to the test project> -p <Path to your test project>
Step 2: Launch AVD - Runner command line. This build step launches the Android virtual device. This step may not be necessary if you decide to run tests on the device itself.
emulator -avd <nameOfYourAvd> -no-boot-anim & sleep 45
And avoid the assembly, which should be interrupted by starting the virtual device (this is the main shell command). The sleep command is used to make AVD ready for the next build step.
Step 3: test release of the application - Ant runner: create a test project, install it on the virtual device
Path to build xml file : <Path to your test project>/build.xml Additional Ant command line parameters : -f <Path to your test project>/build.xml clean debug install -Dsdk.dir=<Path to your android sdk>
Step 4: Unlock AVD - Command Line: Unlock the AVD screen for testing purposes
bash avdUnlock.sh
The body of avdUnlock.sh is here: ( http://pastie.org/7919761 ). This script sends information to a regular AVD port to unlock the screen. This can be improved by sending the command only to a specific port and changing the step of step 2 to add a specific port to the emulator launch. This, however, is not part of this practical
Step 5: Run Tests - Command Line Leader: Run Tests
adb shell pm list instrumentation adb shell am instrument -w <insert your test package ex:com.alth.myproject.test>/com.zutubi.android.junitreport.JUnitReportTestRunner
The first adb command can be removed. This is for debugging purposes only to see what equipment was installed on the device.
Build Step 6: Validation Samples - Command Line Runner: Retrieving Test Reports from a Device
adb pull /data/data/<insert your project package ex:com.alth.myproject>/files/junit-report.xml <report folder>/junit-report.xml
Build Step 7: Final Destruction of the Emulator - Command Line Runner: Kill an existing Android virtual device.
adb emu kill
Additional Build Features: XML Report Processing - Report Type: Ant JUnit
Monitoring rules : <report folder>/*.xml
This How-to is clearly not optimal, but answers the original question. Thus, you can get the report on android functional tests and submit it to teamcity to track the test results.
I hope this helps someone and I will try to answer your questions if you have any.
Al_th
Al_th
source share