How we can skip any Test Cases during CTS Run? - android

How we can do the following task:
During the running time we can skip the any package or case...?

You can not skip the particular test cases directly in CTS. For that you have to execute the Test Cases manually which you want to execute. Since there are thousands of test cases so there is a short way to execute test cases, use the short package name which is common.
eg. you can use $ start --plan CTS -p android.app
So this will executes all the test cases which starts with name android.app, like
android.app.cts.ActivityGroupTest
android.app.cts.AlarmManagerTest
android.app.cts.AlertDialogTest
android.app.cts.InstrumentationTest
and so on...

while running CTS locally we can actually write a .xml file (say foo.xml) which cab be kept under android-cts/repository/plans directory. Test cases under <Entry exclude="class#method;class#method name="package"/> will not be executed for the package.
And then we can run like below example
cts run -s device_ip:port --plan foo
This is helpful while debugging CTS issues

We can skip the particular test case by editing the xml file in the Plans folder .
For eg in the folder
android-cts/repository/plans/CTS.xml
This contains list of all the packages to be executed.Simply delete the package which you want to exclude and save it with other name like
CTS_1.xml and run.
run cts --plan CTS1

Related

Run Python for Android (Qpython) in Android Terminal

Python for Android (Py4A 2.6) is wonderful!!! But QPython (2.7) is a lot more powerful and continuously developed. Now I try to integrate Qpython's Python into Android (5.1 CM12) Terminal / ADB described in this Tutorial:http://wiki.qpython.org/en/diveinto/
My Script to import the environment variables qpython needs looks like:
TERM=screen
PATH=/data/data/com.hipipal.qpyplus/files/bin:/system/bin:/system/xbin
LD_LIBRARY_PATH=.:/data/data/com.hipipal.qpyplus/files/lib/:/data/data/com.hipipal.qpyplus/files/:/data/data/com.hipipal.qpyplus/lib/
PYTHONHOME=/data/data/com.hipipal.qpyplus/files
ANDROID_PRIVATE=/data/data/com.hipipal.qpyplus/files
PYTHONPATH=/storage/emulated/0/com.hipipal.qpyplus/lib/python2.7/site-packages/:/data/data/com.hipipal.qpyplus/files/lib/python2.7/site-packages/:/data/data/com.hipipal.qpyplus/files/lib/python2.7/:/data/data/com.hipipal.qpyplus/files/lib/python27.zip:/data/data/com.hipipal.qpyplus/files/lib/python2.7/lib-dynload/:/storage/emulated/0/com.hipipal.qpyplus/scripts
PYTHONSTARTUP=/storage/emulated/0/com.hipipal.qpyplus/lib/python2.7/site-packages/qpythoninit.py
PYTHONOPTIMIZE=2
TMPDIR=/storage/emulated/0/com.hipipal.qpyplus/cache
AP_HOST=127.0.0.1
AP_PORT=58418
AP_HANDSHAKE=01805a68-c04c-4e21-bd54-ac8732f3a8da
ANDROID_PUBLIC=/storage/emulated/0/com.hipipal.qpyplus
ANDROID_PRIVATE=/data/data/com.hipipal.qpyplus/files
ANDROID_ARGUMENT=/storage/emulated/0/com.hipipal.qpyplus/scripts
Shell session:
u0_a101#C1905:/ $ source /sdcard/qpyenvnew.sh
u0_a101#C1905:/ $ $python
u0_a101#C1905:/ $ hmm do nothing?!
I get no output.
I have found here on Stackoverflow the same Question but the posted solution ist a link how is down.
Other Tutorial on throws only errors
http://dinostest.com/node/28
Try this command in your terminal:
$sh data/data/com.hipipal.qpyplus/files/bin/qpython.sh
Terminal will prompt a Python console.
If your script for the environment variables was obtained by running the code from the tutorial link, it should be correct.
If what you have pasted is exactly what you entered, the problem would be that you tried to run pyhton by typing $python when it should have just been python
Pre-fixing with $ is used to reference the value of a variable, so entering $python referenced the value of the variable python but does nothing with it, hence no feedback.
EDIT2: Although it's not a direct answer to this question I suggest having a look at the App 'Termux'. You can install Python2/3 via apt, virtualenv/-wrapper etc... Much more powerfull!
EDIT: Since /data/data... is only accessible as root, the following must be done as root!
Take care that the python executables path is in your $PATH. That wasn't the case even after having run the script from the tutorial (your script). If it's not present simply type:export PATH=/data/data/com.hipipal.qpyplus/files/bin:$PATH
or follow theses steps. In short: create a file in /sdcard (here ".bashrc") with the above line. After that type: source .bashrcsource init.sh (init.sh is located in /data/data/com.hipipal.qpyplus/files/bin as well) Then fire up Python with python-android5 which is the PIE compatible executable for Phone with Lollipop and above. But be aware: For whatever reason I couldn't exit() or quit() the Python prompt but I was able to run Script from the Terminal! Have fun!
EDIT: I spotted this: PythonForAndroid. It is a fork of PythonForAndroid that is still alive, and this versions are able to run on Android L (Python3 on 5.1.1 in my case). Also check the SL4A linked there, it works great on Lollipop.
Thanks to the answers above I made a super easy solution. If you have root: Create a file "python" and type the following line in it:
sh data/data/com.hipipal.qpyplus/files/bin/qpython-android5.sh
Place this file in your /system/bin directory and you can access python from everywhere using the command 'python'.

How to order test cases for Spoon Automated Testing in Android?

I have added a suite() method to order my tests the way I want them and thus when I run it through Android JUnit they are executed accordingly. But then I noticed that when I use the Spoon execution, the one using cmd, my test cases are executed alphabetically which is the default order.
Why does this happen and how would you counter it without renaming my test cases?
I have the same issue as you; I require a specific order that my test need to be ran in. The app I am testing is too complicated to run in an unpredictable order. My solution was this:
Add this to your build.gradle:
spoon {
if (project.hasProperty('spoonClassName')){
className = project.spoonClassName
}
}
Now, you can execute a specific class with a command like so:
gradle spoon -PspoonClassName=< com.your.pakage.ClassName>
Next, create a file at the root of your Android project: runAllTests.sh
Edit your .sh to look like this:
#!/bin/sh
date +%b-%dT%H.%M > timestamp.out
sites="$HOME"/path/to/project/root
timestamp="$(cat "$sites"/timestamp.out)"
result_folder="$sites"/results
destdir="$result_folder/Results-$timestamp"
mkdir -p "$destdir"
echo "Directory created: ${destdir##*/}"
<---------- Here you start running the test --------------->
echo "Starting Master Setup"
gradle spoon -PspoonClassName=com.espresso.test.MasterSetup
cp -r "$sites"/app/build/spoon "$destdir"/MasterSetup
echo "Results saved to MasterSetup"
echo "Starting WorkoutSchedule"
gradle spoon -PspoonClassName=com.espresso.test.WorkoutSchedule
cp -f "$sites"/app/build/spoon "$destdir"/WorkoutSchedule
echo "Results saved to WorkoutSchedule"
echo "Starting Setting.test"
gradle spoon -PspoonClassName=com.espresso.test.Settings
cp -r "$sites"/app/build/spoon "$destdir"/Settings
echo "Results saved to Settings"
Then, give the script permissions
cd to the script
type chmod u+x runAllTest.sh
You're set. Now just cd to your root, then to execute your test, type . runAllTest.sh.
So, what this does:
First, it creates a timestamp.out. I use this so I can save my results to a file over and over without previous results being overwritten. You do not need this part.
Next, it creates a result folder in the root of your project if it is not already there.
Then, it will make a folder inside the results folder named Results-SOME-DATE.
Lastly, each test will run, saving the results to the normal spot on your project. (Inside build/spoon) Once test are complete it will copy the results to the results folder, and name each test result appropriately so it is easy to see all your tests ran.
NOTE: This script was wrote for MAC. If your on windows or anything else, this script may need modifications.
Additionally: You will find it is inconvenient to open in to each folder to get the index.html opened. So I wrote this script to add to your bash_profile:
function open-results () {
# the browser to open up `index.html' in.
browser='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
# let the user know what directory we're looking in
printf "looking in %s" "$(pwd)"
echo ...
for paths in $(find ./ -name 'debug' -type d); do
for files in $(find "$paths" -name 'index.html'); do
open -a "$browser" "$files"
done
done
echo done
}
Now, cd in terminal to the Results-SOME-DATE, and type open-results. Again, this was written for terminal. You may need to modify depending on your OS. But the structure should be the same
I hope this helps.
The jUnit testing philosophy is that test cases should not depend on each other so order shouldn't be important. That's why you're finding it hard to do. You might want to consider using the "setUp" method to create initial conditions for your test cases rather than having them build on each other.

Android Manifest Instrumentation

I have a android test project setup to test my android project. In the android test project's manifest, I have an entry for instrumentation. It looks like:
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.company.android" />
I'm curious what the point of this entry is, and particuarly what the purpose of android:targetPackage="com.company.android" is for. I ask, because I refactored the old project and put classes into different packages, so I'm curious on what I need to update this value to... is it suppose to point the the package where the class that extends android.app.Application is at?
It tells the build system where to access the actual project you are going to test.
This is necessary because you need access to all your Activities and classes without having extra copies around.
Info about it is scattered around in: http://developer.android.com/tools/testing/testing_android.html
InstrumentationTestRunner is something you use to write Android unit tests.
From the documentation:
Typical Usage
Write TestCases that perform unit, functional, or performance tests against the classes in your package.
Typically these are subclassed from:
ActivityInstrumentationTestCase2
ActivityUnitTestCase
AndroidTestCase
ApplicationTestCase
InstrumentationTestCase
ProviderTestCase
ServiceTestCase
SingleLaunchActivityTestCase
In an appropriate AndroidManifest.xml, define the this instrumentation with the appropriate android:targetPackage set.
Run the instrumentation using "adb shell am instrument -w", with no optional arguments, to run all tests (except performance tests).
Run the instrumentation using "adb shell am instrument -w", with the argument '-e func true' to run all functional tests. These are tests that derive from InstrumentationTestCase.
Run the instrumentation using "adb shell am instrument -w", with the argument '-e unit true' to run all unit tests. These are tests that do notderive from InstrumentationTestCase (and are not performance tests).
Run the instrumentation using "adb shell am instrument -w", with the argument '-e class' set to run an individual TestCase.

Android tests are not executed

I have created a test project with exact the same code as shown here:
http://developer.android.com/tools/testing/testing_ui.html
I have uploaded the jar file in the android virtual device and now I'm ready to run the tests. But I always get this output on the console:
INSTRUMENTATION_STATUS: stream=
Test results for WatcherResultPrinter=
Time: 0.0
OK (0 tests)
INSTRUMENTATION_STATUS_CODE: -1
I have also created a simple test with the following code:
public void FailedTest() throws UiObjectNotFoundException {
assertTrue("This test was executed", false);
}
In case there is something wrong with the code using ui elements.
The package name is Tests and the class name Login so I run the following command:
adb shell uiautomator runtest TestProject.jar -c Tests.Login
Edit
When I run it on a real device I get:
uiautomator: permission denied
As a first step, can you change the name of the test method to match the standard convention used in jUnit 3 i.e. public void testWhatever() { ... } the first 4 letters of the name nust be 'test' in lower case, the signature is public void and the method does not take any parameters.
Similarly, can you change the package name to the more standard lowercase convention e.g. org.example.tests If you file is called Tests.java (and the class also called Tests) then you should be able to call it as follows:
adb shell uiautomator runtest Tests.jar -c com.example.tests.Tests
If these don't help, please can you revise the question to include the entire code from your Tests.java file?
Note: I've not tried to reproduce your code at this stage as I'm travelling. I can do so if my suggestions don't unblock your problem(s).
I'll follow up on the uiautomator: permission denied separately. UI Automator tests do run on real devices. They don't need the device to be rooted. I run them on standard Android 4.2.x devices.

how to execute the test cases of PVplayer in android?

hi can you tell me how to execute the test cases defined in /external/opencore/engines/player/test/src in the donut code?
I have seen the PVplayer documentation , but that does not provide any information.
I am trying to run an SDP file in the PVplayer.
Try to follow the following steps to run the PV Player engine tests (I have done all this with donut code and product Sapphire):
1.You have to include the following line in /external/opencore/Android.mk while making build:
#include $(PV_TOP)/engines/player/test/Android.mk
Either uncomment this (if its commented) or remove any check which is avoiding this line to be included.
2.Build and install the images into phone.
3.Now open shell (use adb shell command). go to directory /system/bin.
There will be an excutable pvplayer_engine_test. Now run the following command:
pvplayer_engine_test -test x y -source xyz.mp4 -logfile -logall
where x is the start test case number and y is the end test
case number.
(For more command line options, please refer pvplayer_engine_unit_test_guide.pdf which is available at /external/opencore/doc location).
Hope this helps.

Categories

Resources