问题
recent i tryied getting started with android uiautomation testing.
The tutorial from the developer site I've worked through a few times and after having some problems and solving them now I have got a bigger issue.
I created a project, imported the two jar files and builded a java testcase scenario (the one from the tutorial.) after that I created an uitest projekt with shell command line. updated the build.xml created a jar file and pushed it onto my device.
As far as good everything worked nicely upon this point.
But tryin to run my tests with the command line:
adb -s <ANDROID_SERIAL> shell uiautomator runtest DeviceUnlocker.jar -c c.d.d.DeviceUnlocker
I only get the error:
INSTRUMENTATION_RESULT: shortMsg = java.lang.RuntimeException
INSTRUMENTATION_RESULT: longMsg=Didn't find class "c.d.d.DeviceUnlockingPseudoCodeTest on Path: /system/framework/android.test.runner.jar: /system/framework/uiautomator.jar:: /data/local/tmp/DeviceUnlocker.jarINSTRUMENTATION_CODE: 0
回答1:
okay the easiest way is to only create inside eclipse a new android junit projekt.
i think this is more or less equal to uiautomator. and i think you might have the same oportunities ... correct me if i'm wrong...
uiautomator is still not running... and i also found some bugs in the uibuild.xml from android itself
<target name="test" description="Runs tests">
<!-- todo: fix this -->
<fail message="Launching tests from Ant not supported yet" />
<exec executable="${adb}" failonerror="true">
<arg line="${adb.device.arg}" />
<arg value="shell" />
<arg value="uiautomator" />
<arg value="runtest" />
<arg value="${out.filename}" />
<arg value="-e" />
<arg value="class" />
<arg value="com.android.uiautomator.samples.skeleton.DemoTestCase" />
</exec>
</target>`
thanks for your help. for me uiautomator is no option anymore. regards
回答2:
- new JavaProjekt (import JUnit android.jar uiautomator.jar
- create packages c.d.d
- Copy TestCase Device Unlocking pseudoTestCase into Projekt
- run cmd 4.1. "set ANDROID_HOME=" to sdk location 4.2. \tools\ android create uitestprojekt -n name -t "android-16" -p projPath
- edit build.xml that was created from create command: added code:
<delete dir="jar"/>
<mkdir dir="jar" />
<javac destdir="bin" encoding="UTF-8" debug="on" target="1.6" includeantruntime="false">
<src path="src" />
</javac>
<jar destfile="jar/uiautomator.jar">
<fileset dir="bin" />
</jar>
- run as antbuild
- cmd -> cd ANDROID_HOME-> cd platform-tools
- adb push /jar/uiautomator.jar data/local/tmp
- adb -s shell uiautomator runtest DeviceUnlocker.jar -c c.d.d.DeviceUnlocker
that were all steps i've done
thanks
回答3:
Make sure you've compiled the java classes into android dex!
I've met the same issue when put a pure java "jar" package to /data/tmp/.
Assume your project is device-unlock
:
cd device-unlock
android create uitest-project -n device-unlock -t 1 -p .
and build
Now you'll find the dexed jar package in bin/device-unlock.jar
, open it with zip you'll see a classes.dex
.
With this jar, it should be ok to continue your test.
回答4:
I had the exact same problem and made a quick haxx to fix it:
Solve it by:
- go to you UiautomationTest project and from the bin/ folder copy the classfile(s). In my case I copied the whole folderstructure com/poc/MyTest.class
- go to the App-Under-Test project and in the bin/ folder past the class data. In my case the com/poc/MyTest.class is merged with the existing classes under com/
- Re-build the UiAutomation project with "ant build"
- re-deploy and now you can run it!
This is just a workaround but it identified the root case - that the testcase class is excluded from the UiAutomator buildstep
回答5:
While running the uiautomator Tests command run it in the below way
Example:
adb shell uiautomator runtest LaunchSettings.jar -c com.uia.example.my.LaunchSettings
adb shell uiautomator runtest "jar name" -c "packagename"."Classname"
This should work.
回答6:
Best way to check this problem is to run this command without using -c <classpath>#<testMethod>
and check if it works.
If it works check for the class name that it prints in the terminal is the one that's used with -c
adb -s shell uiautomator runtest DeviceUnlocker.jar
来源:https://stackoverflow.com/questions/19356650/android-uiautomator-runtest-error-didnt-find-class