Android tests are not executed - android

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.

Related

BDD android Test for Multiple flavored Android Application not working

I am testing an Android application which has product flavors using Cucumber framework(BDD).I am using Cucumber Instrumentation runner for running the features.I started testing for one of the flavor but I am getting the below error:
No tests found. This usually means that your test classes are not in the form that our test runner expects (e.g. doesn't inherit from TestCase or lacks #Test annotations)
Command :
gradlew connectedAndroidTest -Dtags="#login"
Getting the below error:
adb shell am instrument -w -r -e debug false -e class com.example.gviswa200.myapplication.cucumber.steps.StepDefinitions com.example.gviswa200.myapplication.flavor1.test/com.example.gviswa200.myapplication.cucumber.runner.CucumberTestRunner
Error:
Test running failed: Instrumentation run failed due to 'cucumber.runtime.CucumberException'
Empty test suite.
I know the error is due to CucumberTestCase.java not being picked up by the runner CucumberTestRunner, resulting in CucumberException. But I did change the path of the CucumberTestCase.java file several times but still I am getting the same error.
This is my sample android project repo : https://github.com/vsgopinath/AppWithFlavors
I have built the project based on the reference project : https://github.com/sebaslogen/CleanGUITestArchitecture
Let me know if further information is needed.
You must place the test classes in a special folder for any flavor.
that's mean a folder with name androidTest[yourFlavorName]
for example => ( androidTestPaid / androidTestFree )
You must run the tests with a special command for any flavor.
for example => ( gradlew connectedPaidAndroidTest / gradlew connectedFreeAndroidTest )

debug.log for XposedBridge?

I currently work on an application with XposedBridge and I have a lot of questions. I will start with the simple ones.
How can I get the debug.log file?
I cannot find the debug.log file. I have tried the phone shell as well as two adb ways :
A. adb shell data/data/de.robv.android.xposed.installer/log/debug.log
B. adb shell "su -c 'cat data/data/de.robv.android.xposed.installer/log/debug.log'"
C. adb shell cat data/data/de.robv.android.xposed.installer/log/debug.log
adb says : " No such file or directory "
The phone shell can cd to /data and /data/data but not after. Cannot ls neither of the data's. Says access denied. So does adb when I try adb ls.
The phone, Moto E XT1023, is rooted. Despite, shell cannot read some directories. I have posted a question why here but no one seems to care to answer.
I had to go to ES File Explorer. Managed to get to /data. ES says folder empty. Managed to get to Emulator/0/de.robv.android.xposed.installer or something alike. There was a subdirectory called files. Inside was the installer. No debug.log.
Searched all directories with ES for debug.log. Nothing found.
Once I create the XposedBridge class in a separate file of the project and once I do whatever XposedBridge is supposed to do (override methods, insert code before and or after the methods, etcetera) the overridden methods or the methods with code run before and or after or the overridden data will continue to be overridden until the app exits. Is this true?
Is there any simple, yet powerful and comprehensive manual or reference or, the best, a tutorial?
Can I specify another directory for the debug.log.file?
In case I am able to make a directory \data\data manually, would this make the Xposed save debug.log there?
I am so happy I have managed to partially answer the first question which is not only related to XposedBridge but is a global root reach question for rooted phones, so I cannot even think of any other questions for now. I do not have a debug.log but I have error.log and I know how to read these. Here is how in case anyone is interested :
In order to be able to reed XposedBridge log files :
Go to the specialised Moto E adb ( may work with a standard one too ).
Type :
************
* adb root *
************
to ensure root access.
The Dollar Sign $ must appear as the sign before commands. $ means the adb shell environment has been entered.
After $, type :
******
* su *
******
The Sharp Sign # must appear as the sign before commands. # means root has been entered. Once root has been entered, there is a full access to the phone. Thus :
**************************************************
* cd /data/data/de.robv.android.xposed.installer *
**************************************************
can be executed and the directory /data/data/de.robv.android.xposed.installer will be entered.
Type :
******
* ls *
******
to see the contents of this directory.
In case error.log or debug.log files are there, type :
*****************
* cat error.log *
*****************
and or
*****************
* cat debug.log *
*****************
to view these files.
Type :
********
* exit *
********
to return to the safer $ prompt.
Type :
********
* exit *
********
to exit adb.
Note : adb root may not run while a project is developed. The rest works, though.
I still do not have any debug.log. May be the XposedBridge lines do not run. Will check with some simple method from the manual.
Here is what I have found out, though. I have created an empty text file called debug.log on the computer and transferred the file to the main root of the device, the /sdcard directory, themn copied the file to /data/data/de.robv.android.xposed.installer/log just to see what happens. Nothing happens. The file is empty.
Here is what I have found out which may be helpful:
COMMANDS TO READ THE LOG FILES :
adb shell
su
cd /data/data/de.robv.android.xposed.installer/log
cat error.log
USE cp SOURCE DESTINATION after su shell, the # prompt, to copy files from one
directory to another on the device.
IMPORTANT NOTES :
All Xposed classes must be put in xposed_init, otherwise Android Studio 1.2 reports them as never used.
In built.gradle, have :
/* SSB : Added manually so the gradle builds with the
XposedBridgeApi-54.jar which is in the app -> libs
but not to include the jar in the apk. */
dependencies {
provided fileTree(dir: 'libs', include: ['*.jar'])
}
THESE HAVE BEEN PUT MANUALLY.
Update : I have been able to clean the code and have managed to find why I do not have a debug.log. This is because the two XposedBridge classes I have ( one is initialisation of zygote and the other is the work file with hooks and replacements ) are not loaded. The error.log shows : Didn't find class " package ( strts without a com. ) NameOfThePackageWithoutComDot.NameOfTheExposedClass in the NameOfThePackageWithoutComDot-2.apk "
THIS IS SAID FOR THE TWO CLASSES.
Problem partially solved:
I have removed the string " package " from the xposed_init and this solved the problem. Thus, instead of :
package TheNameOfThePackage.TheNameOfTheClass
xposed_init contains :
TheNameOfThePackage.TheNameOfTheClass
without the word " package " in front of the names as Android Studio usually puts and requires.
Now, the custom class seems to load OK and XMain where zygote is init generates a novel.
Regardless, the custom class with the test code works OK. The debug.log file is generated. However, the application does not seem to write in the file and the debug.log only says :
d.xposed.installer/log/debug.log
inside.

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.

How we can skip any Test Cases during CTS Run?

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

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