I am very new to android and learning it for the first time.
On my android project, when I do
gradle build
gradle assembleDebugAndroidTest
I get the application and test apks
So I have these two questions
1) How do I install them on a specific connected device/emulator?
2) How do I start the tests to run on the device ?
Thanks very much.
Run adb devices to see your connected devices:
List of devices attached
emulator-5554 device
emulator-5556 device
Then, use ANDROID_SERIAL to specify the one you want.
To install:
ANDROID_SERIAL=emulator-5554 gradle installDebug
To run tests:
ANDROID_SERIAL=emulator-5554 gradle connectedAndroidTestDebug
Related
I have some number of Android devices in real world, I want to deploy and run new versions of application from git on it.
Currently I use Bitrise to run tests and .apk compilation upon commits, how can I deploy that binaries on my devices and autorun it without user interaction?
I don't know such services/application, but I think there are such services/tools in the world, just I don't know about it.
Edit 1:
My devices are not connected physically, so I can't run gradle to deploy new builds there, devices have access to internet, but they have no direct cable connection to build server.
If your devices connected to CI build machine you need setup execution:
get device list adb devices
1.1 Install app with gradle like "./gradlew installDebug"
1.2 Install app with adb "adb -s your_device install your_app.apk"
Then run specific activity "adb -s your_device shell am start -n com.package.name/com.package.name.ActivityName"
You can write shell script or even create gradle task for this.
I work with titanium studio version 3.0.3
When I run my project into Android device, I got the errors:
[ERROR] : Project failed to build after 287ms
It can not detect my device.
I installed the USB driver for sumsung and i configure Android device by Enable Unknown sources and Enable USB debugging.
In my eclipse IDE, I can detect my device and run my projects without probleme.
Can I give me some help, how can I deploying my projet to android device In titanium Studio
thanks :)
I use the following little script to launch the app on my device:
$SN variable defines the id of the device. You can get it by running adb devices
ti build -p android --build-only;
adb -s $SN uninstall com.example;
adb -s $SN install build/android/bin/applicationName.apk ;
adb -s $SN shell am start com.example/com.example.ActivityName
If you want to keep your application data in place, you should do the following:
adb -s $SN install build/android/bin/applicationName.apk ;
I'm assuming you have configured your PATH correctly.
Launch the script from your application folder.
You will have to change com.example and com.example.ActivityName to match your configuration.
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.
I'm trying to run the sample unit tests for the sample code that ships with the android SDK. Some of the tests run as standard unit tests, no problem. Other tests, such as com.example.android.apis.view.Focus2AndroidTest, use android classes, and therefore need to run in the emulator, that is a problem.
I can run applications just fine in my emulator. When I run tests, though, my emulator starts up, and then just sits there. The test never runs. All I see in the output window in IntelliJ is
Waiting for device.
/Users/rfzabick/android-sdk-mac_x86/tools/emulator -avd MyAvd0 -netspeed full -netdelay none
Device connected: emulator-5554
What am I doing wrong?
EDIT:
After #CrazyCoder's advice, I switched to android 4.0.3 (API 15). Here's what I got:
Testing started at 4:34 PM ...
Waiting for device.
/Users/rfzabick/android-sdk-mac_x86/tools/emulator -avd android4.0.3--api15 -netspeed full -netdelay none -wipe-data -no-boot-anim
Device connected: emulator-5554
Device is online: emulator-5554
Target device: emulator-5554 (android4.0.3--api15)
Uploading file
local path: /Users/rfzabick/IdeaProjects/ApiDemos/out/production/Tests/Tests.apk
remote path: /data/local/tmp/com.example.android.apis.tests
Installing com.example.android.apis.tests
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
Device is not ready. Waiting for 20 sec.
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
Device is not ready. Waiting for 20 sec.
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
Device disconnected: emulator-5554
pkg: /data/local/tmp/com.example.android.apis.tests
Running tests
Test running startedTest running failed: com.android.ddmlib.AdbCommandRejectedException: device not found
Empty test suite.
The only relevant thing I see in logcat is
01-21 16:36:22.047: WARN/ActivityManager(91): No content provider found for permission revoke: file:///data/local/tmp/com.example.android.apis.tests
Can you run normal apps in the emulator or USB device? Try to create the new emulator device and see if helps.
I've tried it with IDEA 11.0.1, 4.0.3 Android platform on Windows and it works fine:
Waiting for device.
Target device: emulator-5554 (ICS)
Uploading file
local path: D:\dev\android-sdk-windows\samples\android-15\ApiDemos\out\production\Tests\Tests.apk
remote path: /data/local/tmp/com.example.android.apis.tests
Installing com.example.android.apis.tests
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
pkg: /data/local/tmp/com.example.android.apis.tests
Success
Running tests
Test running startedFinish
You can also try to restart adb with adb kill-server and start the emulator manually from AVD manager.
Verify that there is no pre-installed ApiDemos application in the emulator, or the signatures will not match. Uninstall existing ApiDemos, then try to deploy and run ApiDemos from IntelliJ IDEA, then try to run the test configuration again.
UPDATE: We did some research and found the source of the problem. By default IntelliJ IDEA sets the dependency scope for the application module inside test module to Compile, so that all the production and test classes get compiled into the single Test.apk.
Instead, the scope must be set to Provided and we'll fix it in the next update. Right now you need to correct it manually as shown on the screenshot:
Rebuild the project and run the tests, again, this time 2 separate apk files will be deployed, one for the main app and the second one for the tests, then tests will run:
Waiting for device.
Target device: emulator-5554 (ICS)
Uploading file
local path: D:\dev\android-sdk-windows\samples\android-15\ApiDemos\out\production\Tests\Tests.apk
remote path: /data/local/tmp/com.example.android.apis.tests
Installing com.example.android.apis.tests
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
pkg: /data/local/tmp/com.example.android.apis.tests
Success
Uploading file
local path: D:\dev\android-sdk-windows\samples\android-15\ApiDemos\out\production\ApiDemos\ApiDemos.apk
remote path: /data/local/tmp/com.example.android.apis
Installing com.example.android.apis
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis"
pkg: /data/local/tmp/com.example.android.apis
Success
Running tests
Test running startedFinish
You can run the instrumentation from ant, from the command line of from a script. In case you prefer the latter this post may be of help.
Running unit tests in emulator is not practical (basically takes too long). And since android jars are usefull only to compiling, it seems impossiblble to run them with unit tests. Good alternative is use of advanced mocking framework ( I personally prefer jMockit,
but there are other )
See example:
https://github.com/ko5tik/andject/blob/master/src/test/java/de/pribluda/android/andject/ViewInjectionTest.java
Here I test my class against derived android activity, and it has to call superclass methods
(this runs in maven, eclipse or IDEA on the spot )
I wrote some test cases for a standard browser app using instrumentationtestcase packages for an android phone.
i am able to run the tests when the phone is connected to pc ..
is there a way to include these test cases in the app in such a way that these test cases are run when an activity is invoked!!
thanks in advance
You could use something like Adb Wireless (requires root) which lets you run and test your applications (from the IDE) but without having a cable.
If what you want is running tests by invoking something from the device... then I don't know if it's possible. But at least it seems very useless... what's the point of running JUnit tests if you cannot see what failed?
I would say yes if I have understood your question correctly.
There is "Dev Tools" available in Android emulator. You just need to create emulator in Eclipse. Then you need to fetch/install this application from emulator to your connected device. After that you install your test project in your device. Then you will be able to run that test project independent of your PC by selecting it from Instrumentation menu option of Dev Tools.
Following are the commands (you can change paths accordingly):
To copy from a running emulator to connected device, execute:
adb -e pull /system/app/Development.apk ./Development.apk
To copies the .apk file into the current directory. Then install it on your connected device with:
adb -d install Development.apk
Hope this was your problem and required solution.