CTS execution using junit categories - android

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

Related

How not to run a particular test when executing connectedAndroidTest?

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?

Gradle: How to run instrumentation test for class

I'm running instrumentation test in Android Studio with Run Configuration defined as below (don't mind warning):
So this is invoking test suit for a specific class. How can I achieve this with command line, I guess using ./gradlew command ?
As stated in the AndroidTestingBlueprint you can use the android.testInstrumentationRunnerArguments.class property:
./gradlew app:connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.android.testing.blueprint.ui.espresso.EspressoTest
According to the docs:
When you run tests from the command-line with Android Debug Bridge
(adb), you get more options for choosing the tests to run than with
any other method. You can select individual test methods, filter tests
according to their annotation, or specify testing options. Since the
test run is controlled entirely from a command-line, you can customize
your testing with shell scripts in various ways.
To run instrumentation tests with adb for a particular class do:
adb shell am instrument -w -e class 'com.myapp.MyActivityTest' com.myapp.test/android.support.test.runner.AndroidJUnitRunner
Note that if you've defined a custom testInstrumentationRunner on your app/build.gradle file then you need to replace android.support.test.runner.AndroidJUnitRunner with your own, like this:
adb shell am instrument -w -e class 'com.myapp.MyActivityTest' com.myapp.test/com.myapp.MyCustomTestRunner
Tip: If you get an error because the command isn't right, know that you can simply get the right command by running the tests from within Android Studio. You'll see the command on the Run window output.
These 2 documentation pages contain execution options:
https://developer.android.com/reference/android/support/test/runner/AndroidJUnitRunner#typical-usage
https://developer.android.com/studio/test/command-line#AMSyntax

Run Android Instrumentation Tests Headless?

I'm not even sure if this makes sense but is it possible to run instrumentation tests in a headless mode? Currently I run my test suite from the command line like so:
ant debug install test
Or if I want to focus on single tests like so:
adb shell am instrument -w -e class com.my.package.testClass#testCase com.my.package.tests/android.test.InstrumentationTestRunner
Is there a flag I can pass to ant or adb (or both) to run the tests without a UI? I'm not using an emulator. I'm running the tests on my device.
It's not a question of running the tests headless, but rather running the emulator headless. Use the -no-window switch when starting the emulator from the command line.

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 ^.^

Run android application with instrumentation turned on

I have created a customised version of android.app.Instrumentation and have modified my AndroidManifest.xml to use it.
However when I run the application from eclipse it does not seem to load my instrumentation object (am logging and settings global (I know horrible, just for now I swear!) variables that I later check)
I think I need to run it using adb and telling it to use instrumentation but I can't find the correct instructions for doing this (and I have read so much about instrumentation the last few days I am start to go nuts!)
Run
$ adb shell pm list instrumentation
to verify that your instrumentation is there. You will receive something like
instrumentation:my.pkg.text/my.instr (target=my.pkg)
then run
$ adb shell am instrument -w my.pkg.test/my.instr

Categories

Resources