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

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

Related

ADB Retrieve list of Class Tests from APK

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.

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?

Android Instrumentation Test Runner: How to filter multiple test annotations

The documentation for instrument is clear on how to filter a single test annotation from a test run:
Filter test run to tests without given annotation: adb shell am instrument -w -e notAnnotation com.android.foo.MyAnnotation com.android.foo/android.test.InstrumentationTestRunner
(from https://developer.android.com/reference/android/test/InstrumentationTestRunner.html)
Is it possible to filter multiple annotations? I have not found a syntax that works thus far. I have tried:
adb shell am instrument -w -e notAnnotation com.android.foo.MyAnnotation -e notAnnotation com.android.foo.AnotherAnnotation com.android.foo/android.test.InstrumentationTestRunner
adb shell am instrument -w -e notAnnotation com.android.foo.MyAnnotation,com.android.foo.AnotherAnnotation com.android.foo/android.test.InstrumentationTestRunner
adb shell am instrument -w -e notAnnotation com.android.foo.MyAnnotation com.android.foo.AnotherAnnotation com.android.foo/android.test.InstrumentationTestRunner
adb shell am instrument -w -e notAnnotation "com.android.foo.MyAnnotation","com.android.foo.AnotherAnnotation" com.android.foo/android.test.InstrumentationTestRunner
and probably others that I've forgotten, thus far to no avail.
Anyone know how to do this?
You should be using AndroidJUnitRunner anyway:
Filter test run to tests without any of a list of annotations:
adb shell am instrument -w -e notAnnotation com.android.foo.MyAnnotation,com.android.foo.AnotherAnnotation com.android.foo/android.support.test.runner.AndroidJUnitRunner

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