CAA
CAA

Reputation: 970

How to solve ClassNotFoundException on uiautomator startup?

I'm trying to create GUI tests for my app with the provided tool(s) from the android-sdk for my app. For the start i've set up a project, as described in http://developer.android.com/tools/testing/testing_ui.html in "Configure your development environment". Currently i've taken the example test from http://developer.android.com/tools/testing/testing_ui.html#sample and put it inside the project UITestsMyAppBasis, in the the package com.MyApp.guitest

the command ant build runs succesfully and i get a jar file in the bin directory of my project. But when i try to start it via:

adb push ./UiTestsMyAppBasis.jar /data/local/tmp
adb shell uiautomator runtest UITestsMyAppBasis.jar -c com.MyApp.guitest

i get the console output:

INSTRUMENTATION_RESULT: shortMsg=java.lang.RuntimeException
INSTRUMENTATION_RESULT: longMsg=com.MyApp.guitest
INSTRUMENTATION_CODE: 0

and the logcat output:

java.lang.RuntimeException: com.MyApp.guitest
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:98)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:85)
    at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:76)
    at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.MyApp.guitest
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    at com.android.uiautomator.testrunner.TestCaseCollector.addTestClass(TestCaseCollector.java:84)
    at com.android.uiautomator.testrunner.TestCaseCollector.addTestClass(TestCaseCollector.java:72)
    at com.android.uiautomator.testrunner.TestCaseCollector.addTestClasses(TestCaseCollector.java:53)
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:95)

i'm using an android emulator with

Setting the chmod on /data/dalvik-cache as described in https://stackoverflow.com/a/13805869/1171328 didn't change the output.

Upvotes: 1

Views: 1016

Answers (2)

arunkumarreddy
arunkumarreddy

Reputation: 177

Best way to check this problem is to run this command without using -c # 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 shell uiautomator runtest UITestsMyAppBasis.jar

Upvotes: 0

Anvesh Yalamarthy
Anvesh Yalamarthy

Reputation: 1693

I believe, this should solve your problem:

-c parameter is used to run the class and not package. so it should be:

adb shell uiautomator runtest UITestsMyAppBasis.jar -c com.MyApp.guitest.<class_name>

Upvotes: 1

Related Questions