ADB Retrieve list of Class Tests from APK - android

I have been tasked with automating a manual test. The manual test had a file of the classes and tests that it referenced when it wanted to run.
Instead of manually looking at the file, is there was a way to retrieve the list of Classes and corresponding Tests via ADB so I can generate my own list(s)?
I do not have access to the source code of the APK.
Example Steps:
adb install -r -g Apples.apk
adb shell pm list instrumentation
instrumentation:com.exampleApples/android.support.test.runner.AndroidJUnitRunner (target=com.exampleApples)
If I wanted to run the full set of tests under a certain class:
adb shell am instrument -w -e class com.exampleApples.GrannySmithTests com.exampleApples/android.support.test.runner.AndroidJUnitRunner
If I wanted to run a specific Test from a Class:
adb shell am instrument -w -e class com.exampleApples.GrannySmithTests#bite com.exampleApples/android.support.test.runner.AndroidJUnitRunner

There's no adb command, but there is dex-member-list, dex-method-list and dex-field-list to list the class members. With Luyten or FernFlower it should also be possible to get the names.

Just do that.
adb shell am instrument -w -e log true -e class com.exampleApples.GrannySmithTests com.hike.chat.stickers.test/android.support.test.runner.AndroidJUnitRunner
This will return you all the classes under com.exampleApples.GrannySmithTests.

Related

How to retrieve adb shell output for string type command?

Usually when I ran my tests I were using following command pattern:
adb shell am instrument -w -r -e package com.myapp.package_with_tests
com.example.test/android.support.test.runner.AndroidJUnitRunner
Because I could include -r parameters I was reading test output in real time and my custom-made software was using this output for more advanced logging.
Lately Android Orchestrator was announced and in order to use it, documentation tells us to use:
adb shell 'CLASSPATH=$(pm path android.support.test.services)
app_process / \
android.support.test.services.shellexecutor.ShellMain am instrument -w -e \
targetInstrumentation com.example.test/android.support.test.runner.AndroidJUnitRunner \
android.support.test.orchestrator/.AndroidTestOrchestrator'
Problem here is that general template looks like this:
adb shell 'some_string_command'
And there -r becomes encapsulated in some other process and I am unable to retrieve output from tests anymore in real time. Actually output after all tests have finished is:
INSTRUMENTATION_RESULT: stream=
Time: 0
OK (0 tests)
Which is incorrect because I had 13 test cases running...
Do you have any idea how can I retrieve output of that process in real time?

How can I run both '#SmallTest' and '#MediumTest' and not '#LargeTest'?

Details:
I want to be able to run all #SmallTest and #MediumTest tests while ignoring #LargeTest tests.
It looks like Android ADB instrumentation commands support negation. For example, you can negate annotation like notAnnotation but I do not see a notSize for size.
Ideally it would be nice to have something similar to: adb shell am instrument -w -e notSize large com.android.foo/android.support.test.runner.AndroidJUnitRunner.
I rather not create custom annotations and then be forced to re-annotate all of my tests.
I have tried the following:
Tried notSize:
adb shell am instrument -w -e notSize large com.android.foo/android.support.test.runner.AndroidJUnitRunner
2 size parameters:
adb shell am instrument -w -e size small -e size medium com.android.foo.MyAnnotation com.android.foo/android.support.test.runner.AndroidJUnitRunner
References
What is the purpose of #SmallTest, #MediumTest, and #LargeTest annotations in Android?
https://developer.android.com/reference/android/test/InstrumentationTestRunner.html
https://developer.android.com/reference/android/support/test/runner/AndroidJUnitRunner.html
Using notAnnotation and specifying the fully qualified path of LargeTest:
adb shell am instrument -w -e notAnnotation android.support.test.filters.LargeTest com.android.foo/android.support.test.runner.AndroidJUnitRunner

android espresso: running test from command line

I have a test.espresso package with all the test classes.
I am trying to run a single test class from the command line, however it ends up running all the test classes.
adb shell am instrument -w \
com.demo.app.test/android.support.test.runner.AndroidJUnitRunner
How do I just run a single test class. I want to use bamboo(which is like jenkins) to run all the test classes individually in separate jobs.
This worked for me (the change is in bold:
adb shell am instrument -w-e class full.path.and.TestClassName\ com.demo.app.test/android.support.test.runner.AndroidJUnitRunner
Based on: https://developer.android.com/studio/test/command-line.html#AMOptionsSyntax (look under options for "class").
If you're using gradle, then there is gradle task you can directly use to achieve it. It would be something like this:
./gradlew connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.
To run on specific flavor:
./gradlew connectedMyAppFlavorDebugAndroidTest
It does everything for you, right from building the app, installing on the connected device, run the tests and finally uninstall the app.
If you're not sure about the exact gradle task you need to execute the tests, run the following to get the all available gradle tasks:
./gradlew tasks
You'll get the list of all the tasks with the short description.
To run via command line
Start device. I use Genymotion so I would do
gmtool admin start DeviceName
Install via command line
For ADB
for ADB is should be exactly what the console outputs from Android studio when you start .
$ adb push /Users/x/x-android/app/build/outputs/apk/x-debug.apk
$ adb shell pm install -r "/data/local/tmp/com.x"
$ adb push /x/x/x-android/app/build/outputs/apk/x-debug-androidTest.apk /data/local/tmp/com.x.test
$ adb shell pm install -r "/data/local/tmp/com.x.test"
For Genymotion it is
gmtool device install ~/Desktop/x.apk
gmtool device install ~/Desktop/x-androidTest.apk
For Genymotion connect Genymotion to ADB
gmtool device adbconnect
Start your tests. This is for both ADB and Geny
adb shell am instrument -w -r -e debug false -e class com.x.MyTest com.x.test/android.support.test.runner.AndroidJUnitRunner
I'm adding also how to run it from Gradle here.
./gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.MyClassTest#myFunctionTest

Java Robotium Android - Run same test simultaneosly on two different devices

I want to run an Android Robotium test on two devices simultaneosly. I couldn't find any solution by now...
To be more precise, I have an application-test.apk wich contains multiple instrumentation classes. I want to run the same test apk, but different test classes on both devices. I know that I can run the tests only in serial mode, with adb.
You can use the -s flag to point an adb command to a specific device. This means that you can just open up two terminals and using the -s flag run both different commands and they will both run in parallel. It is obviously then easy to change this into a script to make it a more scaleable solution.
Example time...
You have two devices connected to your machine and two different test classes you want to run (one on each) on running:
adb devices
you see
List of devices attached
SERIALOFDEVICE1 device1
SERIALOFDEVICE2 device2
then using the serials shown you can then run a command:
adb -s SERIALOFDEVICE1 shell am instrument -w -e class com.android.foo.FooTest1 com.android.foo/android.test.InstrumentationTestRunner
adb -s SERIALOFDEVICE2 shell am instrument -w -e class com.android.foo.FooTest2 com.android.foo/android.test.InstrumentationTestRunner
where
com.android.foo.FooTest1
com.android.foo.FooTest2
Are the classes you want to run on each device.

Running Robotium Test Suite from command line

can anyone please suggest me the way to run a robotium test suite in command line.
adb shell am instrument -w com.package/android.test.InstrumentationTestRunner
This runs all the test cases in that package, but in my app, the tests inside should get executed sequentially. Is there a way to run test suite or individual test cases sequentially from command line?
To run test sequentially
am instrument -w -e class_name#method name package-name/runner
e.g.
am instrument -w -e class com.example.test.class1#test1 com.example.test/android.test.InstrumentationTestRunner`
refer: http://developer.android.com/tools/testing/testing_otheride.html#RunTestsCommand
Yyou can try to run multiple test this way but a better approach is to create a test suite which ensures the sequential execution(order in which you have added the test)
to execute a test suite
adb shell am instrument -w -e class class_name package_name/runner
E.g.
adb shell am instrument -w -e class com.example.test.class1 com.example.test/android.test.InstrumentationTestRunner
If your package name is com.package.test and test class name is test1,you can run the class individually using:
adb shell am instrument -e class com.package.test.test1 -w com.package.test/android.test.InstrumentationTestRunner
I noticed that in robotium tests are ran based off of their name in order. So if you want them sequential you can do
public void test1*test case 1*
{..}
public void test2*test case 2*
{..}
and so on, of course replacing the '*' text with what you want the test case called. Hope this helps ^.^

Categories

Resources