What I want my Perl script to do is..
Run the specific Junit test cases from windows command line.
Uninstall the Apk file from android device or emulator.
I am having difficulty in getting started with 1.For step2 , I guess I can use
adb uninstall package name
Thanks.
You don't have to launch eclipse to run junit test cases.
Try running the Junit tests through script using command line.
More information here. http://www.jsystemtest.org/?q=node/44
Related
I'm facing an issue whereby whenever I use adb command to run my android test case but it keeps a cache of the last test class. This is even though I have changed my code and rebuild.
I'm running below command
./adb shell am instrument -w -e class com.xxx.yyy.tests/SignInActivityTest com.xxx.yyy.test/android.test.InstrumentationTestRunner
I add some test method, it is still caching and run the old test case.
If you are using command line; Make sure to re-build the test application and not only the application under test and that both are deployed to the target before running tests again.
I have created Android unit tests project. They need ADB running for the tests to run successfully.
I have also used the command line tool of Android Debug Bridge for unit testing the Android Unit tests projects.
In above both the cases ADB needs to be running.
Is it possible to run the tests without running ADB. This will be useful for build systems.
If you want to get the errors then you have to use ADB to get the errors.
I want to install android app from local driver on emulator and run tests of espresso on already existing app. Is there any way to skip installation of app in espresso tests?
You could install your apks using ADB and then start the tests manually:
$ adb install myapp.apk (1)
$ adb install myapp-androidTest-unaligned.apk (2)
$ adb shell am instrument -w com.myapp.test/android.support.test.runner.AndroidJUnitRunner (3)
(1) upload your app apk
(2) upload your test apk apk
(3) be sure to use your test apk's package name which is usually your app package name, post-fixed with .test. Also you have to use the fully qualified test runner. This is whatever you specified as the testInstrumentationRunner in your build.gradle file.
To answer your question, you may not need to do steps 1 and 2 if the apk and test apk are already on your device (perhaps by previously running ./gradlew connectedAndroidTest)
Have a look in this Android doc page, it tells a little bit more about the adb shell am instrument commend.
As this was not answered (Maybe did I not find it) previously, I investigated on the following question :
How to perform automated functional tests on Android devices with robotium, and report them to continuous integration server like TeamCity?
As I did not find any answer on that specific question, I investigated. Here is the output of my investigation and a quick How-To in order to help people perform automated functional tests on Android applications using robotium, and then report the results to a continuous integration server like TeamCity. Please note that this may not be the best solution, but I felt that people might be in the same situation as me. So here it is !
The following libraries have been used :
Robotium (https://code.google.com/p/robotium/) : This is an Android test automation framework. It helps you to perform automated tests like click on buttons, fill text automatically, and a lot of other things.
Android Junit Report
(http://zutubi.com/source/projects/android-junit-report/) : This library is very useful to publish test result to an exploitable xml format. If you want to run your tests through Eclipse, you will see the results of your tests on the go, but in order to export them, this library is very useful
Assuming that you have an Android project to test, create an Android Test Project (Eclipse does have a nice workflow to create it for you) and set it up to work with Robotium. A pretty clear detailed instruction on how to do it can be found here : https://code.google.com/p/robotium/wiki/Getting_Started
Then, you need to add Android Junit Report to your project in order to be able to fetch the results of your tests. In order to do so, add the Android Junit Report *.jar library in your lib folder and add it to your build path (in Eclipse : Project -> Properties -> Java Build Path -> Libraries -> Add External Jar).
You also have to 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 should be able to run your tests properly. The results of the tests should be available in your device (in the following folder /data/data//files/junit-report.xml)
The next step is to configure your TeamCity build steps to perform all the different needed action to run your tests. Please note that my solution might not be the optimal one !
Build step 1 : Clean - Command Line runner - This build step may be optional depending of how you decide to create your build.xml files and such build decisions.
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>
Build step 2 : Launch AVD - Command Line runner - This build step launches the android virtual device. This step may be optional if you decide to run the tests on an actual device.
emulator -avd <nameOfYourAvd> -no-boot-anim &
sleep 45
The & avoids build to be interrupted by the virtual device launch (It is basic shell command). The sleep command is used to try to let the AVD be ready for the next build step
Build step 3 : Test app release - Ant runner : Build the 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>
Build step 4 : AVD Unlock - Command line runner : Unlock the AVD screen for testing purpose
bash avdUnlock.sh
Body of avdUnlock.sh here : (http://pastie.org/7919761). This script is sending informations on regular AVD port in order to unlock the screen. This may be improved by sending the command only to a specific port and changing build step 2 to add a specific port to the emulator launch. This is however not really part of this how-to
Build step 5 : Launch tests - Command line runner : Launch the 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 could be removed. This is only for debug purpose in order to see which instrumentation has been installed on the device.
Build step 6 : Fetch tests - Command line runner : Retrieve tests report from the 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 emulator kill - Command line runner : Kill the running 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 answer the original question. Doing so, it is possible to fetch the android functional tests report and feed it to teamcity in order to monitore test results.
I hope this will help someone, and I would try to answer to your questions if you have some.
Al_th
I developed for my application a small suite of Android tests written in Scala that uses the Robotium library. The suite is for all intents and purposes a standard Android JUnit test project and runs successfully if launched from Eclipse.
I've already successfully built and run my main Android application with sbt android-plugin. The main application is located in [ProjectDir]/src/main. I was also able to successfully build my Android test application that is located in the [ProjectDir]/tests/src/main directory. I checked the emulator, and the test application appears to have been correctly installed with android-plugin's tests/android:install-emulator command. However, when I try to run the test project via sbt tests/android:test-emulator, I get:
...
Test results for InstrumentationTestRunner=
Time: 0.001
OK (0 tests)
How I can get sbt android-plugin to recognize that the project contains JUnit tests and run them?
The naming convention used here is the same as the normal JUnit and as such you need to name the tests xxxTest.class. They also need to extend TestCase (AndroidTestCase, InstrumentationTestCase etc...).
To reiterate, eclipse will run a command which will look like:
adb shell am instrument -w -e class com.android.foo.FooTest,com.android.foo.TooTest com.android.foo/android.test.InstrumentationTestRunner
It will append the classes name to the command so naming convention might not apply.
If you run from sbt, it will run
adb shell am instrument -w com.android.foo/android.test.InstrumentationTestRunner
which will find all the classes under the package name of the application com.android.foo which finishes with someClassNameTest.