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 ^.^
Related
CTS execution:
How can we trigger the test suite of Junit by using annotations and categories through command line?
You can run CTS individual test methods or the whole class using android instrumentation command.
For Example: Here in this example CTS test class with a specific method is mentioned to run, you can remove the test method from the below command to run all test methods within the class.
adb shell am instrument -w -e class android.animation.AnimatorSetEventsTest#testCancel
\com.android.frameworks.coretests android.support.test.runner.AndroidJUnitRunner
For more details on running tests via instrumentation follow this link -
https://source.android.com/compatibility/tests/development/instrumentation
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.
I am testing an Android app using command like:
adb shell am instrument -w -e class net.mandaria.test.TippyTipperTest,net.mandaria.test.TippyTipperTest2,net.mandaria.test.TippyTipperTest3 net.mandaria.test/android.test.InstrumentationTestRunner
However, when one of the tests fails, the entire test execution stops. For example, if the first test "net.mandaria.test.TippyTipperTest" fails, I got this output:
net.mandaria.test.TippyTipperTest:INSTRUMENTATION_RESULT: shortMsg=junit.framework.AssertionFailedError
INSTRUMENTATION_RESULT: longMsg=junit.framework.AssertionFailedError: shows enter
INSTRUMENTATION_CODE: 0
My question is:
how can I make it continue to run all the tests, even if the first one fails?
If you use AndroidJUnitRunner:
$ adb shell am instrument -w -r -e debug false -e class com.example.MyClass com.example.test/android.support.test.runner.AndroidJUnitRunner
and if some tests fail the result is printed at the end
...
FAILURES!!!
Tests run: 4, Failures: 2
INSTRUMENTATION_CODE: -1
It takes long to execute some of our instrumented tests. So I'd like not to run them when I run all the other instrumented tests with gradle connectedAndroidTest.
Why don't I annotate those tests with #Ignore? Because I'd like to run them later using adb shell as described here.
Like this:
Running all tests except those in a particular class: adb shell am
instrument -w -e notClass com.android.foo.FooTest
com.android.foo/android.support.test.runner.AndroidJUnitRunner
If I marked those tests ignored and compiled them, it wouldn't be possible to execute them at all.
Is it possible to modify connectedAndroidTest or some other task to reach what I need?
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.